设为首页 加入收藏

TOP

oracle中常用的对象(三)
2014-11-24 02:01:04 来源: 作者: 【 】 浏览:1
Tags:oracle 常用 对象
--------------------维护约束----------------------------------
258
259
--1)增加约束
260 /*
261 如果增加unique, primary key, foreign key,和check约束,那必须使用alter table 语句的add子句
262 如果增加not null约束,那么必须使用alter table语句的modify子句。
263
*/
264
265
alter
table
table
add[constraint conatraint_name
266 constraint_type (column,...);
267
268
alter
table
table modify column
269
[constraint constraint_name
not
null;
270
271
----1增加not null约束
272
alter
table emp02 modify name not
null;
273
274
----2增加unique约束
275
alter
table emp04 add
constraint u_emp04 unique(name);
276
277
----3增加primary key约束
278
alter
table dept01 add
primary
key(dno);
279
280
----4增加foreign key约束
281
alter
table emp01 add dno number(2) references dept01(dno);
282
-----------------------------------------------------------------------------------------------------------------------------------
283
284
select
*
from emp01;
285
286
select
*
from dept01;
287
288
----5增加check约束
289
alter
table emp01 add
check(salary between
800
and
5000);
290
291
292
--2)修改约束名
293 --格式如下:
294
alter
table
table rename constraint old_constraint_name
295
to new_constraint_name;
296
297
--3)删除约束
298
299
--格式如下:
300
alter
table
table
drop
301
constraint constraint_name |
primary
key
[cascade;
302
303
--4)禁止约束
304
305
--格式如下:
306
alter
table
table disable constraint constraint_name [cascade;
307
308
--5激活约束
309
310
--格式如下:
311
alter
table
table enable constraint constraint_name;
312
313
--------------------------------------------------------------------
314
315
--显示约束信息
316
317
/*
318 1,user_constraints :存在于dd之中,可以显示当前用户的所有约束信息
319
320 2,user_cons_columns: 用于显示当前用户约束所对应的表列
321
322
*/
首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ORA-600[17182],ORA-07445[kghrst.. 下一篇oracle导入导出工具exp/imp

评论

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