Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How can i delete the auto increment index?

Author  Topic 

neo_6053
Starting Member

24 Posts

Posted - 2008-11-23 : 21:34:34
How can i delete the auto increment index with query? i want to do it cause i want to import data from ORACLE. bur SQL server set the value of the index column by auto increment.

i tried this code:
quote:
Declare @Index varchar(128)
Declare @Table varchar(128)

Select
SysIndexes.Name As 'Index1',
SysObjects.Name As 'Table1'
Into
#Indexes
From
SysIndexes
Inner Join SysObjects On
SysObjects.id = SysIndexes.id
Where
SysIndexes.Name Is Not Null
and SysIndexes.Name like '_WA_Sys_%'
and SysObjects.XType = 'U'
and SysObjects.name not in ('sysdiagrams','dtproperties')
Order By
SysIndexes.Name,
SysObjects.Name

While (Select Count(*) From #Indexes) > 0
Begin
Set @Index = (Select Top 1 [Index1] From #Indexes)
Set @Table = (Select Top 1 [Table1] From #Indexes)

Exec ('Drop Index [' + @Index + '] On [' + @Table + ']')
Delete From #Indexes Where [Index1] = @Index and [Table1] = @Table
End

Drop Table #Indexes


but if give me error
Cannot drop the index 'Revenue._WA_Sys_00000001_09F52113', because it does not exist or you do not have permission. i wanted to delete all the indexes with prefix "_WA_Sys_" because when i delete the index manually from management studio, i found that the index with prefix "_WA_Sys_" is deleted from sysindexes. So, i guess it's the index for the identity auto increment.

i login as SA but it still says i do not have permission. What's the problem? However, there is 1 condition though. I created the database and restore it with backup from other server. Does it matter? The user is different for both server. However, i did tried to add in the user but it still fail.

How to check who created the indexes? How to check and add authorization for it?

neo_6053
Starting Member

24 Posts

Posted - 2008-11-23 : 22:47:48
i think i might have gone the wrong way from the very beginning.
Should i actually do like this ?
http://www.mssqltips.com/tip.asp?tip=1397

however, he also mention that
"There are some other approaches that you can find on the internet that modify values in the system tables. These approaches do work, but if you make a mistake you could totally mess up your data, so make sure you understand what is in store before modifying system tables"

i have about 400+ tables ... what can i do?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 00:45:04
If its just for one time export you dont have drop the auto increment property. you just need to set identity insert property before import and off it after. some thing like

SET IDENTITY_INSERT yourtable ON

--your import code

SET IDENTITY_INSERT yourtable OFF


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 00:45:47
and if you're using export import wizard you've a property called enable identity insert. just select it while configuring properties.

Also dont use bigger & bolder fonts while posting questions
Go to Top of Page

neo_6053
Starting Member

24 Posts

Posted - 2008-11-24 : 04:02:05
Yup, I found the solution. It's the SET IDENTITY_INSERT yourtable ON.
I fail to do so at 1st because i thought there is no such option for sqlbulkcopy. i was wrong.

http://www.dotnetjunkies.com/WebLog/joshuagough/archive/2005/11/11/133694.aspx

Thx anyway.

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 04:07:25
quote:
Originally posted by neo_6053

Yup, I found the solution. It's the SET IDENTITY_INSERT yourtable ON.
I fail to do so at 1st because i thought there is no such option for sqlbulkcopy. i was wrong.

http://www.dotnetjunkies.com/WebLog/joshuagough/archive/2005/11/11/133694.aspx

Thx anyway.




Welcome
Go to Top of Page
   

- Advertisement -