SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Identity Insert


Identity Insert

Author
Message
mailtoashokberwal
mailtoashokberwal
Valued Member
Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)Valued Member (51 reputation)

Group: General Forum Members
Points: 51 Visits: 52
Comments posted to this topic are about the item Identity Insert
kapil_kk
kapil_kk
SSCertifiable
SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)SSCertifiable (6.5K reputation)

Group: General Forum Members
Points: 6462 Visits: 2774
Easy one to the end of week :-P

_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Danny Ocean
Danny Ocean
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2476 Visits: 1549
Most of people don't know about it because it's not in use in any real scenario. I never use this kind of table in production environment, But i knew it due to someone ask me about it earlier.

Anyway, thanks for question.:-)

Thanks
Vinay Kumar
-----------------------------------------------------------------
Keep Learning - Keep Growing !!!
www.GrowWithSql.com
vinu512
vinu512
SSCarpal Tunnel
SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)SSCarpal Tunnel (4.7K reputation)

Group: General Forum Members
Points: 4717 Visits: 1626
kapil_kk (5/2/2013)
Easy one to the end of week :-P


+1. But good for testing basics...even if its not a real scenario.

Vinu Vijayan

For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden ;-)
Raghavendra Mudugal
Raghavendra Mudugal
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3846 Visits: 2958
good one, thank you for the post. :-)

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Toreador
Toreador
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4229 Visits: 8143
Danny Ocean (5/2/2013)
Most of people don't know about it because it's not in use in any real scenario.


Sure it is, if the table contains other columns, all with defaults.
As a simplistic example:
CREATE TABLE TableA(ID INT IDENTITY (1,1),
LastUpdated datetime default (getdate()))



I don't use this technique often, but have used it in production systems before.
Raghavendra Mudugal
Raghavendra Mudugal
Hall of Fame
Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)Hall of Fame (3.8K reputation)

Group: General Forum Members
Points: 3846 Visits: 2958
Toreador (5/3/2013)
Danny Ocean (5/2/2013)
Most of people don't know about it because it's not in use in any real scenario.


Sure it is, if the table contains other columns, all with defaults.
As a simplistic example:
CREATE TABLE TableA(ID INT IDENTITY (1,1),
LastUpdated datetime default (getdate()))



I don't use this technique often, but have used it in production systems before.


... what Mr. Ocean meant was to use the defaults with the combination of identity column.

(the example what you have given is very nice and we have that set up in the prod server for one database. it actually reduces couple of parameters while inserting - createdate or updating the date)

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Carlo Romagnano
Carlo Romagnano
SSCrazy Eights
SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)SSCrazy Eights (8.4K reputation)

Group: General Forum Members
Points: 8351 Visits: 3411
Danny Ocean (5/2/2013)
Most of people don't know about it because it's not in use in any real scenario. I never use this kind of table in production environment, But i knew it due to someone ask me about it earlier.

Anyway, thanks for question.:-)


A real (especially in old release of sqlserver) scenario is a TALLY table.
[sql]
INSERT INTO TableA DEFAULT VALUES
GO 10000
[/sql]
Another way to insert values in Table A is:
[sql]
SET IDENTITY_INSERT TableA ON
INSERT INTO TableA SELECT TOP 10000 ROW_NUMBER() OVER (ORDER BY A.object_id) FROM sys.objects A, sys.objects B
SET IDENTITY_INSERT TableA OFF
[/sql]
tom.w.brannon
tom.w.brannon
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2143 Visits: 1461
I've learned to read the discussions about all the questions because I learn things there as well. Did not know about adding a number to GO to get multiple executions. THANKS!
manik_anu
manik_anu
Say Hey Kid
Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)Say Hey Kid (691 reputation)

Group: General Forum Members
Points: 691 Visits: 319
Raghavendra Mudugal (5/3/2013)
Toreador (5/3/2013)
Danny Ocean (5/2/2013)
Most of people don't know about it because it's not in use in any real scenario.


Sure it is, if the table contains other columns, all with defaults.
As a simplistic example:
CREATE TABLE TableA(ID INT IDENTITY (1,1),
LastUpdated datetime default (getdate()))



I don't use this technique often, but have used it in production systems before.


... what Mr. Ocean meant was to use the defaults with the combination of identity column.

(the example what you have given is very nice and we have that set up in the prod server for one database. it actually reduces couple of parameters while inserting - createdate or updating the date)


nice explanation... But i have another column in this table "Name" this column is not have default properties.
will this property allow to insert???w00t

Manik
You cannot get to the top by sitting on your bottom.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search