September 23, 2012
DBCC CHECKINDENT can be used to reset a tables identity value. So I will create a small table to demonstrate this. CREATE TABLE Table_1 ( ID INT IDENTITY(1,1) NOT NULL, DateAdded DATETIME NOT NULL ) Insert some rows…. INSERT INTO Table_1(DateAdded) VALUES(GETDATE()); INSERT INTO Table_1(DateAdded) VALUES(GETDATE()); INSERT INTO Table_1(DateAdded) VALUES(GETDATE()); INSERT INTO Table_1(DateAdded) VALUES(GETDATE()); INSERT INTO Table_1(DateAdded) VALUES(GETDATE()); Check the current value which produces the below output…. DBCC CHECKIDENT ('Table_1', NORESEED); Checking identity information: current identity value ’5′, current column value ’5′. DBCC execution completed. If DBCC printed error messages, contact your system administrator. Now we will reset the identity value so that the next time we insert data, the value will be 10…. DBCC CHECKIDENT('Table_1', RESEED, 9); Checking identity information: [...]
Read the full article →
September 19, 2012
I’m going to be looking at sp_change_users_login as a continuation to a previous post where I looked at a couple of ways to transfer logins from one SQL Server to another and touched upon the issue of the orphaned ”security identifier” (SID). A typical scenario that arises is when the DBA quickly realises that the logins on the SQL Server cannot access the database. They try and add the login to the database as a user and are presented with the error: Error 15023: User already exists in current database. sp_change_users_login to the rescue! I first saw this error a number of years ago and due to my complete lack of experience at the time, one of my first thoughts was that I would [...]
Read the full article →