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

Change default IDENTITY to 1,1 #23656

Closed
simon-spier0 opened this issue Apr 21, 2024 · 5 comments · Fixed by #30833
Closed

Change default IDENTITY to 1,1 #23656

simon-spier0 opened this issue Apr 21, 2024 · 5 comments · Fixed by #30833

Comments

@simon-spier0
Copy link

Hello,

Currently, the default IDENTITY is (0,1):
image

However, could you please change it to (1,1) as it has MS SQL Server Management Studio by default?

You must specify both the seed and increment or neither. If neither is specified, the default is (1,1).

Thanks.

@E1izabeth
Copy link
Member

Thank you for request

@E1izabeth
Copy link
Member

I'm unable to reproduce your issue. Could you clarify, how do you create the table to get this behavior?

@E1izabeth
Copy link
Member

Also which DBeaver version do you use?

Sgierek106 added a commit to Sgierek106/dbeaver that referenced this issue May 11, 2024
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)
);
```
@Sgierek106
Copy link
Contributor

I am not the original submitter of this issue, but I encountered this today in DBeaver Community Version 24.0.4.202405051837

In SQL Server, when you create a new identity column for a table and then click "Save", the resulting DDL defaults to an identity seed value of 0, which means the first record inserted into the table gets an id of 0.

@E1izabeth Would you be open to me submitting a PR to fix this?

@E1izabeth
Copy link
Member

@Sgierek106 we're open for contributions, sure. Here is some useful information on this matter https://github.com/dbeaver/dbeaver/wiki/Contribute-your-code

@ShadelessFox ShadelessFox added this to the 24.0.5 milestone May 12, 2024
@MashaKorax MashaKorax self-assigned this May 13, 2024
serge-rider pushed a commit that referenced this issue May 13, 2024
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)
);
```

Co-authored-by: MashaKorax <84867187+MashaKorax@users.noreply.github.com>
@arhayka arhayka added the sp:1 label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants