May 26, 2009 at 7:48 am
I have a table.
Create table emp (id int IDENTITY(1,1))
How to write INSERT statement for this table?
Thanks in advance.
May 26, 2009 at 7:54 am
insert into emp default values
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
May 26, 2009 at 7:58 am
[Code]
set identity_insert emp on
insert into emp(id)
values(1)
set identity_insert emp off
[/Code]
May 26, 2009 at 8:03 am
arup_kc (5/26/2009)
I have a table.Create table emp (id int IDENTITY(1,1))
How to write INSERT statement for this table?
Thanks in advance.
May I ask why you would want such a table?
[font="Verdana"]Markus Bohse[/font]
May 26, 2009 at 11:31 pm
Hi Adi,
Your query workls perfectly.
Hi mayank,
This is not working. It only insetts 1 for every row but not incrementing.
Hi markus,
I should admit that still I have not faced any real time application of this query. This is simply my inquisitiveness. Thanks I have got the answer from Adi.
Thanks to all.
May 27, 2009 at 3:46 am
arup_kc (5/26/2009)
Hi markus,I should admit that still I have not faced any real time application of this query. This is simply my inquisitiveness.
In case you ever need such a table, there are probably easier ways to fill it. Have a look at Jeff's article about implenting and using tally tables.
http://www.sqlservercentral.com/articles/T-SQL/62867/
[font="Verdana"]Markus Bohse[/font]
May 27, 2009 at 4:04 am
Hi Marcus,
Again thanks for this beautiful link.
May 27, 2009 at 6:52 am
arup_kc (5/26/2009)
Hi Adi,Your query workls perfectly.
Hi mayank,
This is not working. It only insetts 1 for every row but not incrementing.
Hi markus,
I should admit that still I have not faced any real time application of this query. This is simply my inquisitiveness. Thanks I have got the answer from Adi.
Thanks to all.
Hi Arup,
You do have to change value for your insert(1 or 2 or 3 any value u want to insert) and it doesn't autoincrements. That method is used to insert rows in an identity table where u have a break in ur identity key sequence due to deletion of rows(1,2,3,4,6(like 5 missing here)) in your table. So if someone wants to insert a particular number, he can do that using that.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply