Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbeaver/dbeaver#23656-Change default IDENTITY to 1,1 #30833

Conversation

Sgierek106
Copy link
Contributor

Closes #23656

When creating an identity column in a SQL Server database, set the default identity seed to 1 instead of 0.

Per Microsoft SQL Server documentation, when creating an identity column, "You must specify both the seed and increment or neither. If neither is specified, the default is (1,1)."

Before fix

CREATE TABLE DatabaseName.dbo.NewTable (
	Id int IDENTITY(0,1) NOT NULL,
	CONSTRAINT NewTable_PK PRIMARY KEY (Id)
);

After fix

CREATE TABLE DatabaseName.dbo.NewTable (
	Id int IDENTITY(1,1) NOT NULL,
	CONSTRAINT NewTable_PK PRIMARY KEY (Id)
);

In SQL Server, when creating an identity column, set the default identity seed to 1 instead of 0.

Per [Microsoft SQL Server documentation](https://learn.microsoft.com/en-us/sql/t-sql/statements/create-table-transact-sql-identity-property?view=sql-server-ver16#increment), when creating an identity column, "You must specify both the seed and increment or neither. If neither is specified, the default is (1,1)."

# Before fix
```
CREATE TABLE DatabaseName.dbo.NewTable (
	Id int IDENTITY(0,1) NOT NULL,
	CONSTRAINT NewTable_PK PRIMARY KEY (Id)
);
```

# After fix
```
CREATE TABLE DatabaseName.dbo.NewTable (
	Id int IDENTITY(1,1) NOT NULL,
	CONSTRAINT NewTable_PK PRIMARY KEY (Id)
);
```
Copy link
Member

@ShadelessFox ShadelessFox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution :^)

@MashaKorax
Copy link
Contributor

verified

@serge-rider serge-rider merged commit cb9d5e8 into dbeaver:devel May 13, 2024
2 checks passed
@Sgierek106 Sgierek106 deleted the dbeaver/dbeaver#23656-sql-server-default-identity-seed branch May 21, 2024 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change default IDENTITY to 1,1
5 participants