postgreSQL 常用命令

postgreSQL跟mysql 一样,是一个免费开源的数据库,它的客户端工具叫psql。

在linux中登录postgreSQL 时一定要先切换用户:

(1)切换用户:  su - postgres
(2)运行 psql -d postgres postgres
参数说明:
-d 是指定数据库名

创建数据库:
create database "HUANGWEI";(正确)
create database 'HUANGWEI';(错误

查看当前有多少个数据库:
select  datname from pg_database;
其中至少有三个数据库:
template0
template1(模板数据库)
postgres

查看当前有多少个用户:
select usename from pg_user;
查看用户的id:
select usename,usesysid from pg_user;

创建用户:
create user user3  with superuser createdb createrole  password 'root';
或:
create user whuang with superuser createdb createrole ;
alter user whuang password 'root';

查看有多少个模式:


查看表所在的模式:
select tablename,schemaname from pg_tables where tablename='student';
查看模式下的所有表:
select tablename,schemaname from pg_tables where schemaname='public';

创建表:
create table member(id int,name char(20),birthday timestamp,regtime date);
插入数据:
insert into 
member values(1,'huangsujie','2012-03-12 20:23:41'::timestamp,'1988-10-06');

函数to_date 的用法:
select to_date('2011-03-22','yyyy-MM-dd');
函数to _timestamp 的用法:
select to_timestamp('2011-03-22-3:34:44','yyyy-MM-dd-HH24:MI:SS');

猜你喜欢

转载自hw1287789687.iteye.com/blog/1452873