Take the 2-minute tour ×

I am trying to write a CREATE TABLE stored proc in T-SQL. This table should have a PK, but I want the PK to automatically seed integer values beginning from 1. Here is the code I have currently but I am getting an error now when I try to add records. How should I define this table instead?

share|improve this question
So where's the code? –  Andriy M Apr 29 '11 at 15:32
Why do you want to do this inside a stored procedure?? I would do this separately, as part of my database creation script(s) - run in SSMS or SQLCMD or something - not on the fly inside a stored proc.... –  marc_s Apr 29 '11 at 15:57
add comment

1 Answer

up vote 2 down vote accepted

Use IDENTITY(1,1), i.e.

  myfield bigint IDENTITY(1,1) PRIMARY KEY,
share|improve this answer
add comment

Your Answer


