неділя, 30 серпня 2009 р.

Auto-increment field

How to create it in

a) MySQL:

CREATE TABLE `t1` ( `id` INT UNSIGNED AUTO_INCREMENT , ... ) AUTO_INCREMENT=... ;

b) PostgreSQL:
first create the sequence:

CREATE SEQUENCE "seq1" INCREMENT BY ... START WITH ... ;

and then - create the table:

CREATE TABLE "t1" ( "id" INT NOT NULL DEFAULT nextval('seq1') ...);

c) Microsoft SQL Server

CREATE TABLE [t1] ( [id] [int] NOT NULL identity(1, 2) ...);

(this means start with 1 and increment by 2 each time )

1 коментар:

  1. This post gives you query for auto increment field. I already knew how to add day in MySQL but Oracle and DB2 are new for me. Your post is useful as we get to know new short cuts. Thanks.
    oracle r12 new features

    ВідповістиВидалити