Loading...
 黯然奮發其 它數據庫各種數據庫創建自增字段方法
rouse life
各種數據庫創建自增字段方法
文 / 郝振強   來源于:黯然奮發

    創建表tb_Test,包含字段tId,tName。
    其中:
        tId為主鍵,自動增長;
        tName常100,唯一限定,非空

 

Sql Server數據庫:

 

/**若表存在則先刪除表**/
if exists (select * from dbo.sysobjects where id = object_id(N'tb_Test') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table tb_Test;

 

/**創建tb_Test**/
create table tb_Test(
    tId int primary key identity(1,1),
    tName varchar(100) not null unique
);

 

Oracle數據庫:

 

--連接Sql plus
Connect test/123456@mms

 

--確保Sequence存在或創建
create sequence SEQUENCE
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
nocache;

 

--創建tb_Test
create table tb_Test(
    tId number(20) primary key,
    tName varchar(100) not null unique
);

 

--通過序列插入自增值
insert into tb_Test(tId,tName) values(sequence.NextVal,'test');

 

Mysql數據庫:

 

--若表存在則先刪除表
drop table if exists tb_Test;

 

--創建tb_Test
create table tb_Test(
    tId int auto_increment primary key,
    tName varchar(100) not null unique
);

 

Access數據庫:

 

--創建tb_Test
create table tb_Test(
    tId antoincrement primary key,
    tName varchar(100) not null unique
);

zhqhao  上傳于[2010-7-26 22:17:47] | Loading... | 【返回頁首】  
icon
相關文章
Loading...
黯然奮發
歡迎投稿 | 審核原則 | 版權說明 | 隱私保護 | 站點地圖
Copyright © 2004-2010 rouse studio All Rights Reserved.
奮發工作室 版權所有 嚴禁轉載
SadToJoy.Com: 豫ICP備05001861號; Techstd.Com: 豫ICP備09031968號
Powered by rouse cms 2.3 © 2009-2010 rouse studio.