在SQL中将auto_increment添加到主键

时间:2022-03-05 21:33:31

I have table named A with column B defined int not null Primary Key and there are 4-5 foreign keys that point to this column already. With what syntax of Alter to make this primary key column be AUTO_INCREMENT ?

我有一个名为A的表,其中列B定义为int not null主键,并且有4-5个外键指向此列。使用Alter的语法使这个主键列成为AUTO_INCREMENT?

3 个解决方案

#1


1  

ALTER TABLE A AUTO_INCREMENT=1

ALTER TABLE A AUTO_INCREMENT = 1

#2


1  

Hi does something like this work?

你喜欢这样的工作吗?

alter table A B int NOT NULL AUTO_INCREMENT

I believe you should use something similar, if you use SQLYog to do it with the user interface then you see in the history tab the corresponding alter command generated.

我相信你应该使用类似的东西,如果你使用SQLYog用户界面来做,那么你在历史记录选项卡中看到生成的相应的alter命令。

#3


1  

If its a primary column go to the table defination, there u can set the auto increment value in the column properties. go to the Column Properties ----> click on identity Specification -----> give the identity increment value and the identity seed value. then for every new row the value will be auto incremented.

如果它的主列转到表格定义,那么你可以在列属性中设置自动增量值。转到列属性---->单击标识规范----->给出标识增量值和标识种子值。然后对于每个新行,该值将自动递增。

#1


1  

ALTER TABLE A AUTO_INCREMENT=1

ALTER TABLE A AUTO_INCREMENT = 1

#2


1  

Hi does something like this work?

你喜欢这样的工作吗?

alter table A B int NOT NULL AUTO_INCREMENT

I believe you should use something similar, if you use SQLYog to do it with the user interface then you see in the history tab the corresponding alter command generated.

我相信你应该使用类似的东西,如果你使用SQLYog用户界面来做,那么你在历史记录选项卡中看到生成的相应的alter命令。

#3


1  

If its a primary column go to the table defination, there u can set the auto increment value in the column properties. go to the Column Properties ----> click on identity Specification -----> give the identity increment value and the identity seed value. then for every new row the value will be auto incremented.

如果它的主列转到表格定义,那么你可以在列属性中设置自动增量值。转到列属性---->单击标识规范----->给出标识增量值和标识种子值。然后对于每个新行,该值将自动递增。