How to set the initialization value of a PRIMARY KEY field defined as IDENTITY in SQL Server?

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 it, 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 ;

So the first record of this table will start with 5 as the value of the id_exemplo field, and so on.

How could you do this in SQL SERVER?

    
asked by anonymous 12.02.2016 / 02:25

1 answer

2

The line that defines this field would look 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
    
12.02.2016 / 02:46