0

I have used identity key in a column of a table like

create table test(testid int identity(1,1),testname varchar(10))

and then I have inserted 2 rows like

Insert into test(testname) values('c')
Insert into test(testname) values('c#')

Now,My table contains like below:

1     c    
2     c#

But,I want insert another row into this table test like 5 c++

So,My table will contain like

1       c   
2       c#  
5      c++

So,please send me the output as soon as possible.Help me please.

2
  • 2
    What have you tried? Commented Jul 8, 2012 at 11:14
  • 1
    Do you really need the testid column to be identity if you have the need to insert arbitrary values into it? Commented Jul 8, 2012 at 14:35

2 Answers 2

4

You can use SET IDENTITY_INSERT:

SET IDENTITY_INSERT test ON;

Insert into test(testid, testname)values(5, 'c++');

SET IDENTITY_INSERT test OFF;

SQL Fiddle.

Sign up to request clarification or add additional context in comments.

Comments

1
SET IDENTITY_INSERT test ON

INSERT test (testid , testname)
VALUES (5, 'c++')

SET IDENTITY_INSERT test OFF

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.