Skip to content

POST - Create new record in a table having IDENTITY primary key column #2097

Answered by yorek
TheGongoDev82 asked this question in Q&A
Discussion options

You must be logged in to vote

You need to use a SEQUENCE instead of an IDENTITY (which is a good practice independently from DAB usage)

CREATE SEQUENCE dbo.GlobalSequence
AS INT START WITH 1;
GO

CREATE TABLE dbo.persons (
	id_person INT PRIMARY KEY DEFAULT(NEXT VALUE FOR dbo.GlobalSequence)
	, first_name VARCHAR(255) NOT NULL
	, last_name VARCHAR(255) NOT NULL
	, date_of_birth DATE
)
GO

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@TheGongoDev82
Comment options

@yorek
Comment options

@TheGongoDev82
Comment options

@yorek
Comment options

Answer selected by TheGongoDev82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants