PostgreSQL 常用语句

 

postgres=# create database mydb;
CREATE DATABASE


postgres=# alter database mydb;
ALTER DATABASE


postgres=# create table mydbtable(name varchar(80),year int);
CREATE TABLE


postgres=# create table mydbtable(name varchar(80),year int);
ERROR:  relation "mydbtable" already exists


postgres=# insert into mydbtable (name,year) values ('xiaoming',23);
INSERT 0 1


postgres=# table mydbtable;
   name   | year 
----------+------
 xiaoming |   23
(1 row)


postgres=# select * from mydbtable;
   name   | year 
----------+------
 xiaoming |   23
(1 row)



postgres=# select name from mydbtable;
   name   
----------
 xiaoming
(1 row)



postgres=# insert into mydbtable (name,year) values ('xiaohong',23);
INSERT 0 1
postgres=# select name from mydbtable;
   name   
----------
 xiaoming
 xiaohong
(2 rows)



postgres=# update mydbtable set name = 'xiaohei' where name='xiaohong';
UPDATE 1
postgres=# select name from mydbtable;
   name   
----------
 xiaoming
 xiaohei
(2 rows)
postgres=# 


postgres=# delete from mydbtable where name='xiaohei';
DELETE 1
postgres=# select name from mydbtable;
   name   
----------
 xiaoming
(1 row)


postgres=# delete from mydbtable;
DELETE 1
postgres=# select * from mydbtable;
 name | year 
------+------
(0 rows)
postgres=# 


postgres=# create database testdb;
CREATE DATABASE


postgres=# alter database testdb;
ALTER DATABASE

 

posted @ 2019-07-16 21:54  anobscureretreat  阅读(1057)  评论(0编辑  收藏  举报