December 19, 2007 at 3:30 am
I have a lot of tables with identity column. I want to remove the identity properties of all the tables while inserting and updating the tables.
December 19, 2007 at 4:10 am
December 19, 2007 at 5:46 am
- Maybe creating a DTS package to load your tables may be the way to go, because it has the option "keep identities"
-If using set identity_insert on, keep in mind you have to list all columns in your insert statement.
e.g.
set identity_insert on
insert into mytable(col1,col2,col333,...)
select * from mysourcetable
set identity_insert off
dbcc checkident('mytable') -- check bol
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
December 24, 2007 at 12:25 am
Hi,
Thanks for your reply. I want to remove the identity properties in the table totally. i.e I want to remove the identity while update also.
December 24, 2007 at 1:30 am
if you want to completely get rid or the usage of the identity property, you'll have to generate drop/create table statements !!
Keep in mind, that there is a purpose for identity ! (automatic increment at insert time.)
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
January 7, 2008 at 12:57 am
I've just received this article and thought it might also help you :
http://www.mssqltips.com/tip.asp?tip=1397
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
January 8, 2008 at 12:03 am
Thanks for your reply. I've nearly 700 tables, and more than 500 tables containing identity column and i want to remove the identity property without dropping/creating the table.
January 8, 2008 at 12:17 am
use sp_msforeachtable to drop the identity column in all tables.
January 8, 2008 at 12:25 am
use sp_msforeachtable to drop the identity column in all tables.
January 8, 2008 at 2:37 am
Hi Kishore,
Thanks for your reply. Let me know how to use this procedure for removing the identity column of all tables. And can you tell me about this procedure.
January 8, 2008 at 12:13 pm
I'm a little confused. Early in the thread it sounded like you want to remove the identity property and retain the data, but your last post sounds like you are okay with dropping the columns with identity property from the tables.
Are you ultimately wanting to have 500 tables with no identity columns?
Greg
Greg
January 8, 2008 at 7:02 pm
balaji_rcs (12/24/2007)
Hi,Thanks for your reply. I want to remove the identity properties in the table totally. i.e I want to remove the identity while update also.
Yeah, uh-huh... what are you going to use to replace the auto-numbering property of the IDENTITY property? Sequence table? Better post that code so we can check it or you'll end up with a bazillion deadlocks per day. SELECT MAX()? Again, better post that code so we can make sure that you won't end up with dupe ID's on a high usage system.
And, then, you might as well convert all of your code to bloody cursors because you're gonna have a hell of a time inserting more than one row at a time no matter which of those two methods you use. If you have a third method not offered above, please post it... I want to see what type of knife you're falling on 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2008 at 7:05 pm
Kishore.P (1/8/2008)
use sp_msforeachtable to drop the identity column in all tables.
Yup... easy to do if no foreign keys... of course, if these IDENTITY columns are being used as the PK for tables, your whole database becomes a useless piece of slag.
C'mon folks! Doesn't anyone else see a problem with this request??? :blink:
--Jeff Moden
Change is inevitable... Change for the better is not.
January 24, 2010 at 11:48 pm
Removing identity property is something I have seen many people doing for some reason.
Most of the time, they perform an additional query to get the next value and then pass it. This method creates additional locks and will not work perfectly in a multi user environment.
I believe identity is one of the good things SQL Server has.
Having said that, there is another way of moving them. It will work better if you do not have foreign keys defined against this table and this table is large.
As of now, it will work only in enterprise edition of SQL Server 2005, but I believe it will work in some additional editions of SQL Server 2008
1. Create another table with the same structure except the identity property.
2. Switch the data from old table to new table
3. Drop the old table (which has the identity property)
4. Rename the new table with proper name.
In case you have soem foreign keys you need to drop the foreign keys and re-create them.
I heard that SQL Server mobile edition has a command where you can simply turn off the identity property, but it is not yet available on other editions.
Cheers,
Prithiviraj Kulasingham
http://preethiviraj.blogspot.com/
January 24, 2010 at 11:50 pm
Oops I just realized that this is quite old thread. I am not sure why it suddenly came into my screen.
Cheers,
Prithiviraj Kulasingham
http://preethiviraj.blogspot.com/
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply