postgresql 刪除 數據庫,表,索引
1. 刪除數據庫
-bash-3.2$ createdb abc -O testuser
CREATE DATABASE
-bash-3.2$ dropdb abc //dropdb刪除數據庫
DROP DATABASE
-bash-3.2$ createdb abc -O testuser
CREATE DATABASE
-bash-3.2$ psql -U testuser -d testuser
Welcome to psql 8.1.23, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
testuser=> drop database abc; //登陸後的刪除數據庫,注意,不能刪除當前登陸的數據庫
DROP DATABASE
//刪除操做的前提是,你是超級用戶,或者是該數據庫的擁有者才行。表也同樣,pgsql有一點很特別,就是庫是你的,表不必定是你的。這個有點搞。
2. 刪除索引
ERROR: cannot drop index testuser_id_pk because constraint testuser_id_pk on table test requires it
HINT: You may drop constraint testuser_id_pk on table test instead.
testuser_test=# drop index unique_name; //刪除索引
DROP INDEX
3. 刪除表 testuser_test=# drop table test,test1; //刪除表 DROP TABLE