您好,登錄后才能下訂單哦!
--創建刪除所有表的存儲過程
CREATE OR REPLACE FUNCTION delAllTable()
RETURNS void
AS
$BODY$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select tablename from pg_tables where tableowner='wxdch';
BEGIN
FOR stmt IN names LOOP
tmp := 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
RAISE NOTICE 'notice: %', tmp;
EXECUTE 'DROP TABLE '|| quote_ident(stmt.tablename) || ' CASCADE;';
END LOOP;
RAISE NOTICE 'finished .....';
END;
$BODY$ LANGUAGE 'plpgsql' VOLATILE;
--執行存儲過程
select * from delAllTable() as temp;
--創建刪除所有序列號的存儲過程
CREATE OR REPLACE FUNCTION delAllSeq()
RETURNS void AS
$BODY$
DECLARE
tmp VARCHAR(512);
DECLARE names CURSOR FOR
select * from pg_class where relowner=(select usesysid from pg_user where usename='wxdch') and relkind='S' ;
BEGIN
FOR stmt IN names LOOP
tmp := 'DROP sequence '|| quote_ident(stmt.relname) || ' CASCADE;';
RAISE NOTICE 'notice: %', tmp;
EXECUTE 'DROP sequence '|| quote_ident(stmt.relname) || ' CASCADE;';
END LOOP;
RAISE NOTICE 'finished .....';
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
ALTER FUNCTION delAllSeq() OWNER TO postgres;
--執行存儲過程
select * from delAllSeq() as temp;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。