设为首页 加入收藏

TOP

Oracle表的创建及相关参数(二)
2015-07-24 10:58:11 来源: 作者: 【 】 浏览:7
Tags:Oracle 创建 相关 参数
XT 1024K PCTINCREASE 0 MINEXTENTS 1 MAXEXTENTS 5) TABLESPACE exampletb 2、 修改表结构 Alter table 表名 add (列名 类型); --添加新列 Alter table 表名 modify (列名 类型); --修改列定义 Alter table 表名 drop column 列名; --删除列 Rename 表名 to 新表名 --改表名(表名前不能加方案名) ALTER TABLE 表名 RENAME COLUMN 当前列名 TO 新列名; --修改列名 ? 修改表结构案例 SQL> Alter table scott.student add (QQ number(10)); --为student表增加列存放QQ号 SQL> Alter table scott.student modify (QQ number(12)); --修改student表中名为QQ的列 SQL> Alter table scott.student rename COLUMN QQ to QQ_num; --将student表中名为QQ的列改名QQ_num SQL> Alter table scott.student drop column QQ_num; --删除student表中名为QQ_num的列 SQL> insert into scott.student(id,name) values(1, 'lucy'); --向student表中插入一条记录 SQL> Alter table scott.student modify (sex char(1) default 'M'); --修改sex列的定义 SQL> insert into scott.student(id,name) values(2, 'Dell'); --向student表中插入一条记录 SQL> Alter table scott.student modify (sex char(1) default null); --修改sex列的定义 SQL> insert into scott.student(id,name) values(3, 'Mary'); --向student表中插入一条记录 思考:oracle中列的默认值设置与修改。 3、 表的约束 Alter table 表名 add constraint 约束 ; --增加一个约束 Alter table 表名 drop constraint 约束名; --删除一个约束 alter table表名enable [validate/novalidate] constraint约束名; --启用一个约束,validate/novalidate代表启用约束时是否对表中原有数据作检查。 alter table表名disable constraint约束名; --禁用一个约束 ? 修改表约束案例 SQL> Alter table scott.student disable constraint st_sex_ck; --禁用st_sex_ck约束 SQL> insert into scott.student(id,name,sex) values(4, 'Lily', 'N'); SQL> Alter table scott.student enable novalidate constraint st_sex_ck; --启用st_sex_ck约束,但不检查已有数据。 SQL> select * from scott.student; SQL> insert into scott.student(id,name,sex) values(5, 'Mark', 'N'); SQL>@$ORACLE_HOME/rdbms/admin/utlexpt1.sql --建立异常数据保存表 或者 @ G:\app\Administrator\product\11.2.0\dbhome_1\RDBMS\ADMIN\utlexpt1.sql --具体路径可以通过搜索utlexpt1.sql获取 SQL>alter table scott.student enable validate constraint st_sex_ck exceptions into exceptions; -- 将异常数据装入异常表 SQL> select * from scott.student where rowid in(select row_id from exceptions); --查看对应的原表中的异常数据 SQL>Alter table scott.student drop constraint st_sex_ck; --删除约束st_sex_ck
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇oracle12c学习之三pdb的可拔插测试 下一篇oracle多行合并成一行

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·微服务 Spring Boot (2025-12-26 18:20:10)
·如何调整 Redis 内存 (2025-12-26 18:20:07)
·MySQL 数据类型:从 (2025-12-26 18:20:03)
·Linux Shell脚本教程 (2025-12-26 17:51:10)
·Qt教程,Qt5编程入门 (2025-12-26 17:51:07)