查看已创建的数据库:select datname from pg_database;
查看所有数据库的详细信息:select * from pg_database
创建数据库:create database wzxdb
删除数据库:drop database wzxdb;
查看已创建的用户:select usename from pg_user;
创建用户并且指定密码:create user wzx with password ‘123456‘
删除用户:drop user wzx;
修改用户密码:alter user wzx with password ‘wzx123456‘
创建数据库并且指定用户:create database wzx with encoding=‘utf8‘ owner=‘wzx‘
查看已创建的表:select tablename from pa_tables;
查看所有表的详细信息:select * from information_schema.tables where table_schema=‘public‘
查看当前数据库的所有表:select * from pg_tables where schemaname = ‘public‘;
创建表结构1:create table wzxstu1(
id int ,
name varchar(10) not Null,
sex varchar(4) ,
age int ,
height float,
registration_time date
);
创建表结构2:create table wzxstu (
name varchar(80), -- 姓名
age int, -- 年龄
height int, -- 身高
resg date -- 注册时间
);
删除表:drop table wzxstu;
删除数据:delete from wzxstu;
插入数据:INSERT INTO wzxstu1 VALUES (1,‘San‘, ‘男‘, 50, 0.25, ‘2019-02-02‘);
删除数据:delete from wzxstu1 where name like ‘wzx%‘;
更新数据:update wzxstu1 set name=‘你好的号‘ where name =‘aa‘
查询数据:
:select * from wzxstu;
:select count(*) from wzxstu;
:select max(age),min(age),count(*) from wzxstu;
:select * from wzxstu order by age ;
:select name from wzxstu group by name order by age;
:select count(*) from kv2;
:select * from kv2 where k like ‘ss%‘;
:select count(v) from kv2 group by v having count(v) >1;
:select count(v) as a from kv2 group by v having a>1
:select distinct name from wzxstu
:select id from wzxstu order by id desc
:select age from wzx order by age desc
:select * from wzxstu limit 1
:select sex,count(*) from wzxstu1 group by sex
查看当前版本信息:select version();
查看当前搜索路径:show search_path;
添加新的模式到搜索路径:set search_path TO myschema,public;