ms sql insert query with identity column

I have a table with four columns

user_id
user
user_desc
staff

the user_id column is an int identity column

and the last column needs to be inserted as a null value

How woudl I write the insert statement for that table?

PryssonAsked:
Who is Participating?
 
RosenetConnect With a Mentor Commented:
In SQL Server it automatically detects the identity column so you don't have to specify it:

insert <table name>
values (@user_val, @user_desc_val, null)

However if that does not work for whatever you reason or you aren't comfortable with implied inserts you can specify the columns:

insert <table name> (user, user_desc, staff)
values (@user_val, @user_desc_val, null)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.