我有一个表,上面有一个约束,我不知道它的名字,因为它是系统生成的,我需要使用脚本删除该约束。
把它放在一个文件中 myscript.sql:
CREATE OR REPLACE PROCEDURE DROP_CONSTRAINT()
LANGUAGE SQL
CALLED ON NULL INPUT
BEGIN ATOMIC
declare myconstraint varchar(128);
declare stmt varchar(2000);
--- select your constraint using the table and column names it consists of
set myconstraint = (select constname from syscat.keycoluse where tabname='MYTABLE' and colname='MYCOL') ;
set stmt = 'alter table mytable drop constraint '|| myconstraint ;
prepare s1 from stmt;
execute s1;
END@
这样称呼它:
db2 -td@ -svf "myscript.sql"
db2 "call DROP_CONSTRAINT()"
db2 "drop procedure DROP_CONSTRAINT"