PostgreSQL common statement

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 = '< span style="color: #800000;">xiaohei' where name='xiaohong'< /span>;
UPDATE
1
postgres
=# select name from mydbtable;
name
----------
xiaoming
xiaohei
(
2 rows)
postgres
=#


postgres
=# delete from mydbtable where name=< span style="color: #800000;">'
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

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 = '< span style="color: #800000;">xiaohei' where name='xiaohong'< /span>;
UPDATE
1
postgres
=# select name from mydbtable;
name
----------
xiaoming
xiaohei
(
2 rows)
postgres
=#


postgres
=# delete from mydbtable where name=< span style="color: #800000;">'
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

Leave a Comment

Your email address will not be published.