SQL表操作
//创建一个名为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;