PostgreSQL database construction, login, Ddl,dml,help, logout, delete library operation

Source: Internet
Author: User
Tags commit create index postgresql prepare psql rollback savepoint wrapper


PostgreSQL Create a database
To create a Xifenfei library using the shell-level createdb command
-bash-3.2$ Createdb Xifenfei
System Authentication Login PostgreSQL Database
Using the Xifenfei database in the psql login PostgreSQL
-bash-3.2$ Psql Xifenfei
Psql (9.4.4)
Type ' help ' for help.
PostgreSQL Simple Query Test
Test SQL operations in PostgreSQL by querying versions, current dates, simple additions, and other SQL statements
xifenfei=#
xifenfei=# SELECT version ();
Version
---------------------------------------------------------------------------------------------------------------
PostgreSQL 9.4.4 on X86_64-unknown-linux-gnu, compiled by GCC (GCC) 4.1.2 20080704 (Red Hat 4.1.2-55), 64-bit
(1 row)

xifenfei=# SELECT current_date;
Date
------------
2015-06-21
(1 row)

xifenfei=# SELECT 2 + 2;
? column?
----------
4
(1 row)
PostgreSQL database Simple DDL and DML tests
By creating tables, inserting/updating/deleting records, deleting tables, and so on
xifenfei=# CREATE TABLE T_xifenfei (ID int,name varchar (100));
CREATE TABLE
xifenfei=# INSERT INTO T_xifenfei values (1, ' www.111cn.net ');
INSERT 0 1
xifenfei=# select * from T_xifenfei;
ID | Name
----+------------------
1 | Www.111cn.net
(1 row)

xifenfei=# INSERT INTO T_xifenfei values (2, ' www.orasos.com ');
INSERT 0 1
xifenfei=# select * from T_xifenfei;
ID | Name
----+------------------
1 | Www.111cn.net
2 | Www.orasos.com
(2 rows)

xifenfei=# Update T_xifenfei set name= ' www.111cn.net ' WHERE id=2;
UPDATE 1
xifenfei=# select * from T_xifenfei;
ID | Name
----+------------------
1 | Www.111cn.net
2 | Www.111cn.net
(2 rows)

xifenfei=# Delete from T_xifenfei where id=2;
DELETE 1
xifenfei=# select * from T_xifenfei;
ID | Name
----+------------------
1 | Www.111cn.net
(1 row)

xifenfei=# drop table T_xifenfei;
DROP TABLE
xifenfei=# select * from T_xifenfei;
Error:relation "T_xifenfei" does not exist
Line 1:select * from T_xifenfei;
^
PostgreSQL database Help using methods
PostgreSQL database Use the \h command to view Help
xifenfei=# \h
Available Help:
ABORT CLUSTER DECLARE EXPLAIN
ALTER AGGREGATE COMMENT DELETE FETCH
ALTER Collation COMMIT Discard GRANT
ALTER conversion COMMIT PREPARED do INSERT
ALTER DATABASE COPY DROP AGGREGATE LISTEN
ALTER DEFAULT Privileges CREATE AGGREGATE DROP CAST LOAD
ALTER DOMAIN CREATE CAST DROP collation LOCK
ALTER EVENT TRIGGER CREATE collation DROP conversion move
ALTER EXTENSION CREATE conversion DROP DATABASE NOTIFY
ALTER FOREIGN DATA wrapper CREATE DATABASE DROP DOMAIN PREPARE
ALTER FOREIGN TABLE CREATE DOMAIN DROP EVENT TRIGGER PREPARE TRANSACTION
ALTER FUNCTION CREATE EVENT TRIGGER DROP EXTENSION Reassign Owned
ALTER GROUP CREATE EXTENSION DROP FOREIGN DATA wrapper REFRESH materialized VI EW
ALTER INDEX CREATE FOREIGN DATA wrapper DROP FOREIGN TABLE REINDEX
ALTER LANGUAGE CREATE FOREIGN TABLE DROP FUNCTION release savepoint
ALTER LARGE OBJECT CREATE FUNCTION DROP GROUP RESET
ALTER materialized VIEW CREATE GROUP DROP INDEX REVOKE
ALTER OPERATOR CREATE INDEX DROP LANGUAGE ROLLBACK
ALTER OPERATOR CLASS CREATE LANGUAGE DROP materialized VIEW ROLLBACK PREPARED
ALTER OPERATOR FAMILY CREATE materialized VIEW DROP OPERATOR ROLLBACK to SavePoint
ALTER role CREATE OPERATOR DROP OPERATOR CLASS savepoint
ALTER rule CREATE OPERATOR CLASS DROP OPERATOR FAMILY Security LABEL
ALTER SCHEMA CREATE OPERATOR FAMILY DROP owned SELECT
ALTER SEQUENCE CREATE role DROP role SELECT into
ALTER SERVER CREATE rule DROP rule SET
ALTER SYSTEM CREATE Schema DROP schema SET CONSTRAINTS
ALTER TABLE CREATE SEQUENCE DROP SEQUENCE SET role
ALTER tablespace CREATE Server DROP Server SET session Authorizati On
ALTER TEXT SEARCH CONFIGURATION CREATE table DROP table SET TRANSACTION
ALTER TEXT SEARCH DICTIONARY CREATE TABLE as DROP tablespace show
ALTER TEXT Search PARSER CREATE tablespace DROP TEXT search CONFIGURATION START TRANSACTION
ALTER Text Search TEMPLATE CREATE text Search CONFIGURATION DROP TEXT search DICTIONARY TABLE
ALTER TRIGGER CREATE TEXT search DICTIONARY DROP TEXT search PARSER TRUNCATE
ALTER TYPE CREATE TEXT search PARSER DROP TEXT search TEMPLATE Unlisten
ALTER USER CREATE TEXT SEARCH TEMPLATE DROP TRIGGER UPDATE
ALTER USER MAPPING CREATE TRIGGER DROP TYPE VACUUM
ALTER VIEW CREATE TYPE DROP USER VALUES
ANALYZE CREATE USER DROP USER MAPPING with
BEGIN CREATE USER MAPPING DROP VIEW
CHECKPOINT CREATE VIEW End
Close Deallocate EXECUTE

xifenfei-# \h CREATE TABLE as
Command:create TABLE as
Description:define A new table from the results of a query
Syntax:
CREATE [[GLOBAL | Local] {temporary | TEMP} | Unlogged] TABLE table_name
[(column_name [,...])]
[With (Storage_parameter [= value] [, ...]) | With OIDs | Without OIDs]
[on COMMIT {PRESERVE ROWS | DELETE ROWS | DROP}]
[Tablespace Tablespace_name]
As query
[with [NO] DATA]
PostgreSQL Exit Login
xifenfei-# \q
-bash-3.2$
PostgreSQL Delete Database
-bash-3.2$ dropdb Xifenfei
-bash-3.2$ Psql Xifenfei
Psql:FATAL:database "Xifenfei" does not exist

Contact: mobile Phone (13429648788) QQ (107644445)

Link:http://www.xifenfei.com/5943.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.