Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - SQLserver self-growing column
SQLserver self-growing column
If your table has a self-growing column, you can use the following statement to do it once, and you can ensure that the code will not insert duplicate values.

Declare @ namevarchar (4);

-Max (id) is the maximum value of the self-growing column id.

set @ name =(right(' 0000 '+convert(varchar(5),((select max(id)from table)+ 1),4));

-print @ name;

Insert into table value (@ name);

Select * from table