- /建测试表
- create table dept( -----部门表
- deptno number(3) primary key,
- dname varchar2(10),
- loc varchar2(13)
- );
- create table employee_info( ----emplpoyee表
- empno number(3),
- deptno number(3),
- ename varchar2(10),
- sex char(1),
- phone number(11),
- address varchar2(50),
- introduce varchar2(100)
- );
- --
- //0.重命名
- //0.1 表:rename dept to dt; ---将dept重命名为dt;
- rename dt to dept; ---将dt改回dept表
- //0.2 列:alter table dept rename column loc to location;
- alter table dept rename column location to loc;
- //1.添加约束
- //1.1 primary key
- alter table employee_info add constraint pk_emp_info primary key(empno);
- //1.2 foreign key
- alter table employee_info add constraint fk_emp_info foreign key(deptno)
- references dept(deptno);
- //1.3 check
- alter table employee_info add constraint ck_emp_info check
- (sex in ('F','M'));
- //1.4 not null
- alter table employee_info modify phone constraint not_null_emp_info not null;
- //1.5 unique
- alter table employee_info add constraint uq_emp_info unique(phone);
- //1.6 default
- alter table employee_info modify sex char(2) default 'M';
- //2.添加列
- alter table employee_info add id varchar2(18);
- alter table employee_info add hiredate date default sysdate not null;
- //3.删除列
- alter table employee_info drop column introduce;
- //3.修改列
- //3.1 修改列的长度
- alter table dept modify loc varchar2(50);
- //3.2 修改列的精度
- alter table employee_info modify empno number(2);
- //3.3 修改列的数据类型
- alter table employee_info modify sex char(2);
- //3.4 修改默认值
- alter table employee_info modify hiredate default sysdate+1;
- //4.禁用约束
- alter table employee_info disable constraint uq_emp_info;
- //5.启用约束
- alter table employee_info enable constraint uq_emp_info;
- //6.延迟约束
- alter table employee_info drop constraint fk_emp_info;
- alter table employee_info add constraint fk_emp_info foreign key(deptno)
- references dept(deptno)
- deferrable initially deferred;
- //7.向表中添加注释
- comment on table employee_info is 'information of employees';
- //8.向列添加注释
- comment on column employee_info.ename is 'the name of employees';
- comment on column dept.dname is 'the name of department';
- //9.清除表中所有数据
- truncate table employee_info;
- //10.删除表
- drop table employee_info;
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
Oracle RAC 一键安装翻车?手把手教你如何排错!
Lucifer三思而后行
553次阅读
2025-04-15 17:24:06
【纯干货】Oracle 19C RU 19.27 发布,如何快速升级和安装?
Lucifer三思而后行
475次阅读
2025-04-18 14:18:38
Oracle SQL 执行计划分析与优化指南
Digital Observer
451次阅读
2025-04-01 11:08:44
XTTS跨版本迁移升级方案(11g to 19c RAC for Linux)
zwtian
449次阅读
2025-04-08 09:12:48
墨天轮个人数说知识点合集
JiekeXu
445次阅读
2025-04-01 15:56:03
【ORACLE】记录一些ORACLE的merge into语句的BUG
DarkAthena
439次阅读
2025-04-22 00:20:37
Oracle数据库一键巡检并生成HTML结果,免费脚本速来下载!
陈举超
415次阅读
2025-04-20 10:07:02
【ORACLE】你以为的真的是你以为的么?--ORA-38104: Columns referenced in the ON Clause cannot be updated
DarkAthena
414次阅读
2025-04-22 00:13:51
Oracle 19c RAC更换IP实战,运维必看!
szrsu
394次阅读
2025-04-08 23:57:08
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
363次阅读
2025-04-17 17:02:24