加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgreSQL 常用命令

发布时间:2020-12-13 18:23:20 所属栏目:百科 来源:网络整理
导读:postgreSQL跟mysql 一样,是一个免费开源的数据库,它的客户端工具叫psql。 在linux中登录postgreSQL 时一定要先切换用户: (1)切换用户: su - postgres (2)运行 psql -d postgres postgres 参数说明: -d 是指定数据库名 创建数据库: create database

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');

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读