pgsql commonly used commands

Connect to the database, the default user and the database is Postgres
psql -d dbname -U the User

Switching database, corresponding to the mysql dbname use
\ C dbname
include a database, corresponding to the mysql Databases Show
\ L
include tables corresponding to Tables mysql the Show
\ dt
Display structure corresponds tblname desc, Show Columns from tbName
\ D tblname

\ Di View Index 

Create a database: 
the Create Database [database name]; 
delete the database: 
drop Database [database name];  
* rename a table: 
the ALTER the Table [table name A] rename to [table name B]; 
* Delete a table: 
drop the Table [table name]; 

* Add the existing table fields: 
the ALTER the Table [table name] add column [field name] [type]; 
* delete fields in the table: 
the ALTER the Table [table name] drop column [field name]; 
* Renaming a field:  
ALTER table [table] rename column [field name a] to [name field B]; 
* to set a default value field:  
ALTER table [table] alter column [field name] set default [new default ];
* removed default:  
ALTER table [table] alter column [field name] drop default; 
insert data in the table: 
iNSERT INTO table name ([field name m], [field name n], .... ..) values ([column values of m], [n the value of the column], ......); 
a data table in a column of a row modifications: 
Update [table] SET [target field name] = [target] where [the line feature]; 
delete a row of data in the table: 
the delete from [table name] where [the line feature]; 
the delete from [table name]; - delete empty the entire table 
to create the table: 
create table ([Field Name 1] [Type 1] <references associated table name (associated with the field name)>;, [2 Field Name] [Type 2], ...... <, primary key (field name m , the field name n, ...)>;); 

\ copyright show PostgreSQL use and distribution terms
\ encoding [character encoding name]
                 Display or set the client character encoding
\ h [name] SQL command syntax for instructions on using * All commands
\ prompt [text] name
                 prompt the user sets the internal variable
\ password [USERNAME]
                 Securely The Change password for user A
\ Q exit psql

 

Guess you like

Origin www.cnblogs.com/vzhangxk/p/11599018.html