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
 General SQL Server Forums
 New to SQL Server Programming
 insert values in to a table which is having identity column

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-02-08 : 09:43:44
Arif writes "I want to insert values in to a table which is having identity column, how? can you help me out from this problem.


Thanks in advance

Jamal"

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-02-08 : 09:46:34
You want to insert value in identity column or in other columns?

To insert value in identity column:

Set IDENTITY_INSERT <table-name> ON
GO
INSERT INTO ....
GO
SET IDENTITY_INSERT <table-name> OFF
GO


To insert row in table with identity column:

insert into Tbl(col1, col2, col3)  -- don't include identity column
values(...)


[Edit]: My mistake!! Table name should be added as a part of SET IDENTITY_INSERT statement

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

elpuerco
Starting Member

10 Posts

Posted - 2007-04-03 : 09:51:32
When I try to do this I get an error (Incorrect syntax near the keyword 'ON'.)

SET IDENTITY_INSERT ON
GO
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-04-03 : 10:16:48
You have missed the part in RED, the table name.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-04-03 : 11:39:15
quote:
Originally posted by Peso

You have missed the part in RED, the table name.


Peter Larsson
Helsingborg, Sweden



Do you have ESP or something?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-04-03 : 13:42:02
ESP? Extra-Special Poster?

e4 d5 xd5 Nf6
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-04-04 : 02:44:47
or Extra-Sensory perception?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -