Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

add primary key with auto increment sql server

/*
--Syntax for MySQL
MySQL uses the AUTO_INCREMENT keyword to perform an auto-increment feature.
By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.
*/
CREATE TABLE Persons (
    Personid int NOT NULL AUTO_INCREMENT,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int,
    PRIMARY KEY (Personid)
);

/* Syntax for SQL Server: */
CREATE TABLE Persons (
    Personid int IDENTITY(1,1) PRIMARY KEY,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Age int
);

/* Syntax for Oracle: */
CREATE SEQUENCE seq_person
MINVALUE 1
START WITH 1
INCREMENT BY 1
CACHE 10;
 
PREVIOUS NEXT
Tagged: #add #primary #key #auto #increment #sql #server
ADD COMMENT
Topic
Name
8+1 =