postgresql 刪除 數據庫,表,索引

ehbg5391 8年前發布 | 11K 次閱讀 PostgreSQL 數據庫服務器

來自: http://my.oschina.net/jimyao/blog/612695


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
 本文由用戶 ehbg5391 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!