How to set the boot value of a PRIMARY KEY field set to IDENTITY in SQL Server?

Asked

Viewed 358 times

0

In Mysql when creating a table with an AUTO_INCREMENT field being PRIMARY KEY it is possible to define what will be the initialization value of the first record of the same, as follows the script below:

CREATE TABLE IF NOT EXISTS `tb_exemplo` (
  `id_exemplo` int(11) primary key auto_increment NOT NULL,
  `nm_exemplo` varchar(100),
  `dt_registrado` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `dt_alterado` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

Thus the first record of this table will start with 5 as the field value id_exemplo, and from it on.

inserir a descrição da imagem aqui

How would it be possible to do this in SQL SERVER?

1 answer

2


The line that defines this field would be something like:

[id_exemplo] [int] IDENTITY(5,1) PRIMARY KEY NOT NULL,
-- IDENTITY(x,y) em que x é o primeiro valor e y o incremento para cada novo registo

Browser other questions tagged

You are not signed in. Login or sign up in order to post.