Search
 
SCRIPT & CODE EXAMPLE
 

SQL

create table sql server auto increment primary key


/* mysql server */
CREATE TABLE persons (
    id int NOT NULL AUTO_INCREMENT,
    colour varchar(191) NOT NULL,
    created datetime, 
    modifed datetime
);

/* sql server IDENTITY*/
CREATE TABLE persons (
    id int IDENTITY(1,1) PRIMARY KEY,
    colour varchar(191) NOT NULL,
    created datetime, 
    modifed datetime
);

INSERT INTO persons (colour, created, modified)
VALUES ('red','2022-08-05', '2022-08-05'),
VALUES ('green','2022-08-05', '2022-08-05'),
VALUES ('blue','2022-08-05', '2022-08-05');
Comment

create table sql server auto increment primary key


/* mysql server */
CREATE TABLE persons (
    id int NOT NULL AUTO_INCREMENT,
    colour varchar(191) NOT NULL,
    created datetime, 
    modifed datetime
);

/* sql server IDENTITY*/
CREATE TABLE persons (
    id int IDENTITY(1,1) PRIMARY KEY,
    colour varchar(191) NOT NULL,
    created datetime, 
    modifed datetime
);

INSERT INTO persons (colour, created, modified)
VALUES ('red','2022-08-05', '2022-08-05'),
VALUES ('green','2022-08-05', '2022-08-05'),
VALUES ('blue','2022-08-05', '2022-08-05');
Comment

create table with primary key auto increment in sql

CREATE TABLE table_name (
    id INT NOT NULL IDENTITY(1, 1),
    name NVARCHAR (100) NULL,
    school NVARCHAR (100) NULL,
    PRIMARY KEY (ID)
);
Comment

create table with primary key auto increment in sql

CREATE TABLE table_name (
    id INT NOT NULL IDENTITY(1, 1),
    name NVARCHAR (100) NULL,
    school NVARCHAR (100) NULL,
    PRIMARY KEY (ID)
);
Comment

SQL Auto Increment Primary Key - SQL Server

-- using IDENTITY(x, y) to auto increment the value
-- x -> start value, y -> steps to increase
CREATE TABLE Colleges (
  college_id INT IDENTITY(1,1),
  college_code VARCHAR(20) NOT NULL,
  college_name VARCHAR(50),
  CONSTRAINT CollegePK PRIMARY KEY (college_id)
);

-- inserting record without college_id
INSERT INTO Colleges(college_code, college_name)
VALUES ("ARD13", "Star Public School");
Comment

SQL Auto Increment Primary Key - SQL Server

-- using IDENTITY(x, y) to auto increment the value
-- x -> start value, y -> steps to increase
CREATE TABLE Colleges (
  college_id INT IDENTITY(1,1),
  college_code VARCHAR(20) NOT NULL,
  college_name VARCHAR(50),
  CONSTRAINT CollegePK PRIMARY KEY (college_id)
);

-- inserting record without college_id
INSERT INTO Colleges(college_code, college_name)
VALUES ("ARD13", "Star Public School");
Comment

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;
Comment

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;
Comment

sql create tabel with primary key auto_increment code

CREATE TABLE books (
  id              INT           NOT NULL    IDENTITY    PRIMARY KEY,
  title           VARCHAR(100)  NOT NULL,
  primary_author  VARCHAR(100),
);
Comment

sql create tabel with primary key auto_increment code

CREATE TABLE books (
  id              INT           NOT NULL    IDENTITY    PRIMARY KEY,
  title           VARCHAR(100)  NOT NULL,
  primary_author  VARCHAR(100),
);
Comment

PREVIOUS NEXT
Code Example
Sql :: how to check nls timestamp format in oracle 
Sql :: duplicate column values sql 
Sql :: apex ORA-20999 
Sql :: How to select the nth row in a SQL database table? 
Sql :: mysql show carset 
Sql :: output to file mysql 
Sql :: sql get table last modified time 
Sql :: oracle db create new schema 
Sql :: reutrn string after character sql 
Sql :: list index mysql cli 
Sql :: date_format for time sql 
Sql :: how to describe a table in sqlite3 
Sql :: how to delete a column in sql 
Sql :: sql column values comma separated 
Sql :: alter table change default 
Sql :: v$session table or view does not exist 
Sql :: oracle current sequence value 
Sql :: postgres list tables and row counts 
Sql :: mysql shell ERROR: Not connected. 
Sql :: group_concat order by 
Sql :: oracle sql timestamp 
Sql :: select count of distinct values sql 
Sql :: HOW TO FIND MEDIAN IN SQL FOR BOTH IDD AND EVEN 
Sql :: what is mysql_pconnect 
Sql :: use of now() in mysql 
Sql :: sql random number between 1000 and 9999 
Sql :: join to find results not in another table 
Sql :: postgres create type 
Sql :: delete a record from a table sqlite3 
Sql :: mysql docker compose 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =