简体   繁体   English

将值添加到 SQL 服务器中的标识 (1,1) 列

[英]Add values to an identity(1,1) column in SQL Server

I have two tables:我有两张桌子:

CREATE TABLE project.teacher 
(
    PROFESSOR_Codigo SMALLINT IDENTITY( 100, 1),
    birth            DATE NOT NULL,
    phone            VARCHAR(15)
);

CREATE TABLE project.student
(
    STUDENT_Codigo IDENTITY( 1, 1),
    birth          DATE NOT NULL,
    phone          VARCHAR(15)
);

When I add a student to the student table it will increment 1 from the number 1, and stay (1, 2, 3, 4, 5, 6, ...)当我将学生添加到学生表时,它将从数字 1 增加 1,并保持 (1, 2, 3, 4, 5, 6, ...)

In the teacher table I already have data entered, and start with a value of 100 in the identity column, but when I add 1, it gets identity 1, not 101在教师表中,我已经输入了数据,并从标识列中的值 100 开始,但是当我添加 1 时,它得到标识 1,而不是 101

I've tried everything, scope_identity() , @@identity , but I couldn't?我已经尝试了一切, scope_identity()@@identity ,但我做不到? Does anyone have any ideas?有没有人有任何想法?

What I do to insert a row into the teacher table:我要在教师表中插入一行:

INSERT INTO project.student 
VALUES ('1998-05-08', '963597461');

INSERT INTO project.teacher
VALUES ('1994-05-09', '968413692');

try尝试

dbcc checkident(teacher, noreseed)

this will return the current identity value of the ident column.这将返回 ident 列的当前标识值。 your create statement is fine so maybe something went wrong on the on create?您的创建语句很好,所以创建时可能出现问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM