For PostgreSQL database, here are the common commands for your own PostgreSQL
In Windows DOS window connection database, the default user and database is Postgres
Psql-u user-d dbname
switch databases, equivalent to MySQL's use dbname
\c dbname
Enumerate the databases, equivalent to the MySQL show databases
\l
List table, equivalent to the MySQL show tables
\dt
View table structure, equivalent to desc tblname,show columns from Tbname
\d Tblname
\di View Index
To create a database:
Create DATABASE [DB name];
To delete a database:
drop database [DB name];
* Rename a table:
ALTER TABLE [table name a] rename to [table name B];
* Delete a table:
drop table [table name];
* Add fields to existing tables:
ALTER TABLE [table name] Add column [Field name] [type];
To delete a field from a table:
ALTER TABLE [table name] Drop column [field name];
Modify Database Column Properties
ALTER TABLE name ALTER COLUMN name Type name (350)
Rename a field:
ALTER TABLE [table name] Rename column [field name a] to [field name B];
* Set a default value for a field:
ALTER TABLE [table name] ALTER column [field name] Set default [new default value];
* Remove default values:
ALTER TABLE [table name] ALTER column [Field name] drop default;
To insert data into a table:
Insert into table name ([Field name m],[field name N],......) VALUES ([column M's Value],[column N's value],......);
To modify the data for a column of a row in a table:
Update [table name] set [Target Field name]=[target value] where [character of the row];
To delete a row of data from a table:
Delete from [table name] where [characteristic of the row];
Delete from [table name];--erase entire table
To create a table:
Create TABLE ([field name 1] [type 1];, [field Name 2] [type 2],...... <,primary key (field name m, field name N,...) >;);
\copyright display of PostgreSQL usage and release terms
\encoding [character encoding name]
Display or set the user-side character encoding
\h [name] SQL command syntax description, with * Show all commands
\prompt [Text] Name
Prompt user to set internal variables
\password [USERNAME]
Securely change the password for a user
\q Exit Psql
Can be done using pg_dump and Pg_dumpall. For example, back up the sales database:
Pg_dump Drupal>/opt/postgresql/backup/1.bak
Below two points, I think more important:
- PostgreSQL is case-sensitive for table names and field names. the graphical interface can be created normally. Use the SQL statement with double quotes, if the JDBC query, etc., remember to use the escape symbol.
- PostgreSQL is insensitive to casing in SQL statements such as the Select ID from T_user and the select ID from T_user, which queries the ID from the T_user table. This field. If you want to query the fields in uppercase letters, double quotation marks are also added: select "ID" from T_user
PostgreSQL Common Commands