1+ <!-- SECCIÓN AUTO-INCREMENT -->
2+ < div id ="auto-increment-section ">
3+ < div id ="adsense-container " style ="width: 350px; position: absolute; left: 0px; "> </ div >
4+ < div class ="inner-modal ">
5+ < div class ="inner " style ="padding: 0px; ">
6+ < h1 > AUTO INCREMENT Field</ h1 >
7+
8+ < p > Auto-increment allows a unique number to be generated automatically when a new record is inserted into a
9+ table.
10+ Often this is the primary key field that is created automatically for each new record.</ p >
11+
12+ < h2 > MySQL Syntax</ h2 >
13+ < pre > < code class ="language-sql "> CREATE TABLE Persons (
14+ Personid int NOT NULL AUTO_INCREMENT,
15+ LastName varchar(255) NOT NULL,
16+ FirstName varchar(255),
17+ Age int,
18+ PRIMARY KEY (Personid)
19+ );
20+
21+ -- Start AUTO_INCREMENT with another value
22+ ALTER TABLE Persons AUTO_INCREMENT=100;
23+
24+ -- Insert without specifying Personid
25+ INSERT INTO Persons (FirstName, LastName)
26+ VALUES ('Lars','Monsen');</ code > </ pre >
27+
28+ < h2 > SQL Server Syntax</ h2 >
29+ < pre > < code class ="language-sql "> CREATE TABLE Persons (
30+ Personid int IDENTITY(1,1) PRIMARY KEY,
31+ LastName varchar(255) NOT NULL,
32+ FirstName varchar(255),
33+ Age int
34+ );
35+
36+ -- Tip: Start at 10, increment by 5
37+ -- Personid int IDENTITY(10,5) PRIMARY KEY
38+
39+ INSERT INTO Persons (FirstName, LastName)
40+ VALUES ('Lars','Monsen');</ code > </ pre >
41+
42+ < h2 > MS Access Syntax</ h2 >
43+ < pre > < code class ="language-sql "> CREATE TABLE Persons (
44+ Personid AUTOINCREMENT PRIMARY KEY,
45+ LastName varchar(255) NOT NULL,
46+ FirstName varchar(255),
47+ Age int
48+ );
49+
50+ -- Tip: Start at 10, increment by 5
51+ -- AUTOINCREMENT(10,5)
52+
53+ INSERT INTO Persons (FirstName, LastName)
54+ VALUES ('Lars','Monsen');</ code > </ pre >
55+
56+ < h2 > Oracle Syntax</ h2 >
57+ < p > Oracle requires a sequence object to implement auto-increment:</ p >
58+ < pre > < code class ="language-sql "> -- Create sequence
59+ CREATE SEQUENCE seq_person
60+ MINVALUE 1
61+ START WITH 1
62+ INCREMENT BY 1
63+ CACHE 10;
64+
65+ -- Insert using nextval
66+ INSERT INTO Persons (Personid, FirstName, LastName)
67+ VALUES (seq_person.nextval, 'Lars', 'Monsen');</ code > </ pre >
68+ </ div >
69+ </ div >
70+ </ div >
0 commit comments