1

Say I have a table that looks like:

ID Name Age Co 1 Adls 15 US 2 sldkl 14 FR 3 sldke 16 UK 4 sldee 17 IN 

I want to add values to the table and have the ID incremented. ID is the primary key, and I set is Identity under column properties to 'Yes' and identity increment to 1.

So basically, I am doing:

Insert Into TableName(Name, Age, Co) Values(slkdje, 19, CH) (sldjklse, 20, AU) (slfjke, 12, PK) 

But, I am getting errors that the primary key is null, and therefore this operation in invalid. How would I add the values, but get the primary key values to increment?

8
  • 3
    There is an AUTO_INCREMENT you can set on a column, see: Auto Increment. Commented Oct 18, 2018 at 22:33
  • What does SHOW CREATE TABLE TableName give? Please add to your question... Commented Oct 18, 2018 at 22:33
  • 1
    There's no 'column properties' in MySQL . You must be using some kind of 'front end' application Commented Oct 18, 2018 at 22:37
  • 1
    Some how your identity did not stick. Check it again. Commented Oct 18, 2018 at 23:07
  • 2
    In SQL Server Management Studio, right click that table, go to "Script Table As" and select "CREATE to". This will give the script for the table creation. Please add that into this post. Commented Oct 18, 2018 at 23:08

1 Answer 1

1

here is a great example for what you want here

here is also a sql query that is copy and paste that will show my example.

create table #temp( ID int IDENTITY(1,1) PRIMARY KEY, LastName varchar(255) NOT NULL, FirstName varchar(255), Age int ) insert into #temp(LastName) values('billy'),('bob') select * from #temp drop table #temp; 

hope this helps dude.

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

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.