码迷,mamicode.com
首页 > 数据库 > 详细

SQL表操作

时间:2015-10-27 11:00:47      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

//创建一个名为TEST1的表空间

CREATE SMALLFILE TABLESPACE "TEST1" DATAFILE ‘G:\ORACLE_11G\ORADATA\ORCL\TEST1‘ SIZE 100M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO; 

//创建一个名为DD的用户

-- Create the user 
create user DD
default tablespace TEST1
temporary tablespace TEMP
profile DEFAULT
password expire;

 

//创建一个表,列,数据类型,是否为空

-- Create table
create table T_HQ_TXL
(
name VARCHAR2(20) not null,
sex CHAR(1),
telephone NUMBER
)
tablespace TEST
pctfree 10
initrans 1
maxtrans 255;

//为列添加注释

-- Add comments to the columns 
comment on column T_HQ_TXL.name
is ‘姓名‘;
comment on column T_HQ_TXL.sex
is ‘性别:1-男;2-女‘;
comment on column T_HQ_TXL.telephone
is ‘电话‘;
comment on column T_HQ_TXL.relationship
is ‘关系‘;

//创建主键约束,外键约束
-- Create/Recreate primary, unique and foreign key constraints 
alter table T_HQ_TXL
add constraint PK_HQ_TXL primary key (NAME)
using index 
tablespace TEST
pctfree 10
initrans 2
maxtrans 255;
alter table T_HQ_TXL
add constraint UQ_HQ_SEX unique (SEX)
using index 
tablespace TEST
pctfree 10
initrans 2
maxtrans 255;
alter table T_HQ_TXL
add constraint FK_HQ_GX foreign key (RELATIONSHIP)
references T_HQ_GX (GUANXI);

//创建检查约束
-- Create/Recreate check constraints 
alter table T_HQ_TXL
add constraint CHECK_SEX
check (sex = ‘1‘ or sex = ‘2‘);

 

//创建的关系参照表

-- Create/Recreate primary, unique and foreign key constraints 
alter table T_HQ_GX
drop constraint PK_HQ_GX cascade;
alter table T_HQ_GX
add constraint PK_HQ_GX primary key (GUANXI)
using index 
tablespace TEST
pctfree 10
initrans 2
maxtrans 255;

SQL表操作

标签:

原文地址:http://www.cnblogs.com/OldZhao/p/4913232.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!