Oracle(3)-----DDL语句

思维导图

一.create语句

    语句格式:

create table 表名
(
    列1名 列类型 约束,--约束有5种primary key,not null,unique,check,foreign key
    列2名 列类型 约束,
    .
    .

    constraint 约束名 约束类型
)

    可以直接定义表的结构:表名,列名,列类型,默认值,约束

create table student
(
    sno number(10),
    sname varchar2(10) not null,
    ssex varchar2(2) not null,
    sdream varchar2(10) default 'no' unique,	

    constraint student_pk primary key(sno),
    constraint student_sdream check(sdream is not null),
    constraint student_sno foreign key(sno) references student_no(sno)
);

    也可以通过已有的表建立新表

create table student2 as (select * from student);

二.alter语句

语句格式:

alter table 表名
[add 列名 列类型 默认值 约束 |       --添加列
 modify 列名 列类型 默认值 约束 |    --修改列
 rename column 列名 to 新列名 |     --重命名列
 drop column 列名 |                --删除列
 add constraint 约束名 约束类型 |   --添加约束
 drop constraint 约束名 |          --删除约束
 enable constraint 约束名 |        --启用约束
 disable constraint 约束名 |       --停用约束
]

    添加一列

alter table student add sclass varchar2(10) default 'no' not null;

    修改一列

alter table student modify sclass number(10) default 10;

     改列名

alter table student rename column sclass to class;

    删除一列

alter table student drop column class;

   添加约束

alter table student add constraint studnet_sno primary key(sno);

    删除约束

alter table student drop constraint studnet_sno;

    使约束生效   

alter table student enable constraint student_sno;

    使约束失效

alter table student disable constraint student_sno;

三.drop语句

语句格式:

drop table 表名 (cascade constraints)  --级联删除,删除这个表的同时删除和该表有关系的其他对象

删除表

drop table student cascade constraints;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值