大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
主键约束 SQL> alter table customers add constraint customers_pk primary key (customer_id); Table altered. col constraint_name for a30 col constraint_type for a15 col table_name for a30 col index_name for a30 SQL> select constraint_name,constraint_type,table_name,index_name,status from dba_constraints where constraint_type = 'P' and owner = 'SOE'; CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME INDEX_NAME STATUS ------------------------------ --------------- ------------------------------ ------------------------------ -------- CUSTOMERS_PK P CUSTOMERS CUSTOMERS_PK ENABLED col constraint_name for a30 col constraint_type for a15 col table_name for a30 col column_name for a30 SQL> select dba_cons_columns.constraint_name, dba_cons_columns.table_name, dba_cons_columns.column_name, dba_cons_columns.position from dba_constraints join dba_cons_columns on (dba_constraints.constraint_name = dba_cons_columns.constraint_name) where constraint_type = 'P' and dba_constraints.owner = 'SOE'; CONSTRAINT_NAME TABLE_NAME COLUMN_NAME POSITION ------------------------------ ------------------------------ ------------------------------ ---------- CUSTOMERS_PK CUSTOMERS CUSTOMER_ID 1 禁用约束 SQL> alter table customers disable constraint customers_pk; 启用约束 SQL> alter table customers enable constraint customers_pk; 删除约束 SQL> alter table customers drop constraint customers_pk; 外键约束 SQL> alter table orders add constraint orders_customer_id_fk foreign key (customer_id) references customers (customer_id); Table altered. col constraint_name for a30 col constraint_type for a20 col table_name for a20 col r_constraint_name for a30 col delete_rule for a15 SQL> select constraint_name,constraint_type,table_name,r_constraint_name,delete_rule,status from dba_constraints where constraint_type = 'R' and owner = 'SOE'; CONSTRAINT_NAME CONSTRAINT_TYPE TABLE_NAME R_CONSTRAINT_NAME DELETE_RULE STATUS ------------------------------ -------------------- -------------------- ------------------------------ --------------- -------- ORDERS_CUSTOMER_ID_FK R ORDERS CUSTOMERS_PK NO ACTION ENABLED col child_table_name for a20 col father_table_name for a20 col child_column_name for a20 col father_column_name for a20 SQL> select dba_cons_columns.constraint_name, dba_cons_columns.table_name as child_table_name, dba_cons_columns.column_name as child_column_name, dba_cons_columns.position, dba_indexes.table_name as father_table_name, dba_ind_columns.column_name as father_column_name from dba_constraints join dba_cons_columns on (dba_constraints.constraint_name = dba_cons_columns.constraint_name) join dba_indexes on (dba_constraints.r_constraint_name = dba_indexes.index_name) join dba_ind_columns on (dba_indexes.index_name = dba_ind_columns.index_name) where constraint_type ='R' and dba_constraints.owner = 'SOE'; CONSTRAINT_NAME CHILD_TABLE_NAME CHILD_COLUMN_NAME POSITION FATHER_TABLE_NAME FATHER_COLUMN_NAME ------------------------------ -------------------- -------------------- ---------- -------------------- -------------------- ORDERS_CUSTOMER_ID_FK ORDERS CUSTOMER_ID 1 CUSTOMERS CUSTOMER_ID 1、普通外键约束(如果存在子表引用父表主键,则无法删除父表记录) SQL> alter table orders add constraint orders_customer_id_fk foreign key (customer_id) references customers (customer_id); 2、级联外键约束(可删除存在引用的父表记录,而且同时把所有有引用的子表记录也删除) SQL> alter table orders add constraint orders_customer_id_fk foreign key (customer_id) references customers (customer_id) on delete cascade; 3、置空外键约束(可删除存在引用的父表记录,同时将子表中引用该父表主键的外键字段自动设为NULL,但该字段应允许空值) SQL> alter table orders add constraint orders_customer_id_fk foreign key (customer_id) references customers (customer_id) on delete set null;创新互联主营北辰网站建设的网络公司,主营网站建设方案,成都APP应用开发,北辰h5重庆小程序开发搭建,北辰网站营销推广欢迎北辰等地区企业咨询
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。