新聞中心
DB2表管理的相關(guān)語(yǔ)句是學(xué)習(xí)DB2數(shù)據(jù)庫(kù)系統(tǒng)的基礎(chǔ)知識(shí),下面就為您詳細(xì)介紹一些DB2表管理語(yǔ)句,希望對(duì)您學(xué)習(xí)DB2表管理方面能有所幫助。

創(chuàng)新互聯(lián)專業(yè)提供重慶服務(wù)器托管服務(wù),為用戶提供五星數(shù)據(jù)中心、電信、雙線接入解決方案,用戶可自行在線購(gòu)買重慶服務(wù)器托管服務(wù),并享受7*24小時(shí)金牌售后服務(wù)。
創(chuàng)建表
CREATE TABLE BOOKS
( BOOKID INTEGER,
BOOKNAME VARCHAR(100),
ISBN CHAR(10) )
使用like創(chuàng)建表
CREATE TABLE MYBOOKS LIKE BOOKS
制定表空間
db2 create table T1 (c1 int ...) in TS1
db2 create table T2 (c1 float ...) in TS1
刪除表
drop table tab_name
添加刪除列
db2 => create table test (c1 int)
DB20000I The SQL command completed successfully.
db2 => alter table test add c2 char(8)
DB20000I The SQL command completed successfully.
db2 => alter table test drop c2
DB20000I The SQL command completed successfully.
列的修改及限制
1.修改長(zhǎng)度
alter table tab_name alter c1 set data type varchar(20)
2.設(shè)置為非空
alter table tab_name alter c1 set not null
create table tab_name (id interger not null)
3.設(shè)置默認(rèn)值
create table tab_name (id integer,name varchar(10) with default 'none')
4.為列創(chuàng)建序列
使用關(guān)鍵字 generated always as identity
create table tab_name (id integer generated always as identity (start with 1,increment by 1))
5.唯一性約束
使用關(guān)鍵字primary key
create table tab_name (id int not null primary key)
使用關(guān)鍵字unique
alter table tab_name add constraint unique (id)
create unique index idx_name on tab_name (id)
6.檢查性約束
使用關(guān)鍵字check
ALTER TABLE BOOKS ADD BOOKTYPE CHAR(1) CHECK (BOOKTYPE IN ('F','N') )
7.參照約束
使用關(guān)鍵字references
CREATE TABLE AUTHORS (AUTHORID INTEGER NOT NULL PRIMARY KEY,
LNAME VARCHAR(100),
FNAME VARCHAR(100))
CREATE TABLE BOOKS (BOOKID INTEGER NOT NULL PRIMARY KEY,
BOOKNAME VARCHAR(100),
ISBN CHAR(10),
AUTHORID INTEGER REFERENCES AUTHORS)
文章名稱:DB2表管理語(yǔ)句
文章轉(zhuǎn)載:http://fisionsoft.com.cn/article/coohjsj.html


咨詢
建站咨詢
