Oracle删除表主键语句删除⽆名主键语句:
SELECT*FROM USER_CONS_COLUMNS WHERE TABLE_NAME ='表名';
ALTER TABLE表名DROP CONSTRAINT主键名称;
上⾯语句需要⼿动,如何⾃动执⾏?看下⾯:
CREATE OR REPLACE FUNCTION DEL_TABLE_CONSTRAINT (tb_name      VARCHAR2,
field_name    VARCHAR2)
RETURN NUMBER
IS
con_count  NUMBER;
con_name    VARCHAR2 (32);
BEGIN
drop删除表con_name :='';
con_count :=0;
SELECT COUNT (DISTINCT constraint_name)
INTO con_count
FROM user_cons_columns
WHERE    table_name =UPPER (tb_name)
AND column_name =UPPER (field_name)
AND ROWNUM =1;
IF con_count >0
THEN
SELECT DISTINCT constraint_name
INTO con_name
FROM user_cons_columns
WHERE    table_name =UPPER (tb_name)
AND column_name =UPPER (field_name)
AND ROWNUM =1;
EXECUTE IMMEDIATE
'alter table '|| tb_name ||' drop constraint '|| con_name;
END IF;
RETURN0;
END;
这样执⾏
DECLARE
a  NUMBER;
BEGIN
a := DEL_TABLE_CONSTRAINT ('表名', '字段名');
END;
/

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。