Friday, February 26, 2010

Drop User: The database principal owns a schema in the database, and cannot be dropped

This is a common error when dropping a user from a database when it owns some schema. Usually you can use SSMS UI to uncheck the user from the owned schema.

After locating the owned schema by the user, the correct sql statement to change the owner of a schema is:

alter authorization on schema::schema_name to user_name

Thursday, February 18, 2010

How to reset a remote desktop session when you can't remote desktop to the target server

A refusing remote server can be annoying when you have ever tried to connect to it because of some urgent issue.

Solution is in this link.

Understanding the Identity column

Here is the original article.

A common problem encountered by most DBA's is to insert values into a table with an identity column and "set identity_insert on table_name on" should be used.

Three quick ways to show the last identity value that was just inserted:

select SCOPE_IDENTITY()

select @@IDENTITY

select ident_current('table_name')


The differences between them are stated in the above linked article.

Another important command for reseeding the identity column is:

DBCC CHECKIDENT('table_name', RESEED, 1)