sql文件内容:
\connect wxdch
--创建存储过程
CREATE OR REPLACE FUNCTION delData()
RETURNS boolean
AS
$BODY$
DECLARE
rec RECORD;
sql varchar;
BEGIN
FOR rec IN select * from pg_tables where schemaname='public' LOOP
--删除表内容
sql:='truncate table '||rec.tablename;
execute sql;
END LOOP;
return true;
END;
$BODY$ LANGUAGE 'plpgsql' VOLATILE;
--执行存储过程
select * from delData() as temp;
bat文件内容:
@echo off
echo PostgreSQL8.4 Version is starting
echo Please wait ........
cd \
@echo off
REM PostgreSQL server psql runner script for Windows
REM Dave Page, EnterpriseDB
SET server=localhost
SET port=5432
SET username=postgres
SET dbname=wxdch
SET PGPASSWORD=HHXTGLY
SET DbScript=c:\windows\system32\delData.sql
REM Run psql
"e:\database\bin\psql.exe" -U %username% -f %DbScript% -a -h %server% -p %port%
pause