| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
ehbg5391
8年前发布

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 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1454333300276.html
PostgreSQL 数据库服务器