pg数据库执行sql文件_在postgresql中通过命令行执行sql文件
pg数据库执⾏sql⽂件_在postgresql中通过命令⾏执⾏sql⽂件General
\copyright show PostgreSQL usage and distribution terms
\g [FILE] or ; execute query (and send results to file or |pipe)
\h [NAME] help on syntax of SQL commands, * for all commands
\q quit psql
Query Buffer
兵马俑门票价格\e [FILE] [LINE] edit the query buffer (or file) with external editor
\ef [FUNCNAME [LINE]] edit function definition with external editor
\p show the contents of the query buffer
\r reset (clear) the query buffer
\s [FILE] display history or save it to file
\w FILE write query buffer to file
Input/Output
\copy ... perform SQL COPY with data stream to the client host
\echo [STRING] write string to standard output
\i FILE execute commands from file
\o [FILE] send all query results to file or |pipe
\qecho [STRING] write string to query output stream (see \o)
Informational
(options: S = show system objects, + = additional detail)工商银行网银登陆
\d[S+] list tables, views, and sequences
\d[S+] NAME describe table, view, sequence, or index
\da[S] [PATTERN] list aggregates
\db[+] [PATTERN] list tablespaces
\dc[S] [PATTERN] list conversions
\dC [PATTERN] list casts
\dd[S] [PATTERN] show comments on objects
\ddp [PATTERN] list default privileges
\dD[S] [PATTERN] list domains
\det[+] [PATTERN] list foreign tables英雄联盟点券
\des[+] [PATTERN] list foreign servers
\deu[+] [PATTERN] list user mappings
\dew[+] [PATTERN] list foreign-data wrappers
\df[antw][S+] [PATRN] list [only agg/normal/trigger/window] functions \dF[+] [PATTERN] list text search configurations
\dFd[+] [PATTERN] list text search dictionaries
\dFp[+] [PATTERN] list text search parsers
\dFt[+] [PATTERN] list text search templates
\dg[+] [PATTERN] list roles
\di[S+] [PATTERN] list indexes
\dl list large objects, same as \lo_list
\dL[S+] [PATTERN] list procedural languages
\dn[S+] [PATTERN] list schemas
\do[S] [PATTERN] list operators
\dO[S+] [PATTERN] list collations
\dp [PATTERN] list table, view, and sequence access privileges
\drds [PATRN1 [PATRN2]] list per-database role settings
\ds[S+] [PATTERN] list sequences
\dt[S+] [PATTERN] list tables
\dT[S+] [PATTERN] list data types
\du[+] [PATTERN] list roles
\dv[S+] [PATTERN] list views
\dE[S+] [PATTERN] list foreign tables
\dx[+] [PATTERN] list extensions
\l[+] list all databases
\sf[+] FUNCNAME show a function's definition
\z [PATTERN] same as \dp
Formatting
\a toggle between unaligned and aligned output mode
\C [STRING] set table title, or unset if none
\f [STRING] show or set field separator for unaligned query output
\H toggle HTML output mode (currently off)
\pset NAME [VALUE] set table output option
(NAME := {format|border|expanded|fieldsep|footer|null|
numericlocale|recordsep|tuples_only|title|tableattr|pager})
\t [on|off] show only rows (currently off)
\T [STRING] set HTMLtag attributes, or unset if none
\x [on|off] toggle expanded output (currently off)
Connection
\c[onnect] {[DBNAME|- USER|- HOST|- PORT|-] | conninfo}
connect to new database (currently "postgres")
\encoding [ENCODING] show or set client encoding
\password [USERNAME] securely change the password for a user
\conninfo display information about current connection
Operating System
\cd [DIR] change the current working directory
\timing [on|off] toggle timing of commands (currently off)
\! [COMMAND] execute command in shell or start interactive shell
Variables
\prompt [TEXT] NAME prompt user to set internal variable
\set [NAME [VALUE]] set internal variable, or list all if no parameters
\unset NAME unset (delete) internal variable
Large Objects
\lo_export LOBOID FILE
\lo_import FILE [COMMENT]
\lo_list
\lo_unlink LOBOID large object operations
postgresql数据管理系统使⽤命令⽅式有两种:
1. 内部命令,以反斜线开始 \ ,如: \l 显⽰所有数据库
2. 标准SQL命令,以分号 ; 或 \g 结束,可以使⽤多⾏
数据库的关键操作:
1. 启动服务
2. 登录
3. 建⽴数据库
4. 建⽴表
5. 插⼊记录到表中
6. 更新/删除/查询/修改操作
7. 退出
8. 停⽌服务
在windows7中安装的postgresql默认使⽤GBK字符集,经常不能使⽤显⽰中⽂的数据表,解决办法:注意:在windows 7下的postgresql中写操作时要使⽤GBK,读操作时要⽤UTF8;
设置字符集为 utf-8 就可以了.
postgres=# \encoding utf-8 // 设置客户端的字元集秋天的心情短句
postgres=# \encoding // 显⽰客户端的字元集
postgres=# show client_encoding; // 显⽰客户端的字元集
postgres=# show server_encoding; // 显⽰服务器的字元集
启动服务:
net start postgresql-9.5
停⽌服务:
怎么给文件夹设密码net stop postgresql-9.5
获取命令帮助:
c:\> psql --help
登录( 注意: postgres 是默认⽤户即管理员 ):
路径 psql -h 服务器 -U ⽤户名 -d 数据库 -p 端⼝地址 // -U 是⼤写
C:\> psql -h localhost -U postgres -p 5432 // 默认打开postgres数据库
C:\> psql -h 127.0.0.1 -U postgres -d fengdos -p 5432 // 打开fengdos数据库C:\> psql -U postgres // 快速登录(全部使⽤默认设置)
// 使⽤某些有密码的⽤户的情况下, 会提⽰输⼊密码.
⽤户 postgres 的⼝令: ILoveYou // 输⼊时不会显⽰任何字符
// 成功后显⽰:
psql (9.5.3)
输⼊ "help" 来获取帮助信息.
// 进⼊postgresql数据库系统提⽰符状态, ******=# 中=#前⾯为当前使⽤的数据库postgres=# help // 获取系统帮助,显⽰如下:
您正在使⽤psql, 这是⼀种⽤于访问PostgreSQL的命令⾏界⾯
键⼊:
\copyright显⽰发⾏条款
\h显⽰ SQL 命令的说明
\?显⽰ pgsql 命令的说明 (pgsql内部命令)
\g 或者以分号(;)结尾以执⾏查询
\q退出注: 数据库名称区分⼤⼩写的。
postgres=# \help // 获取SQL命令的帮助,同 \h
postgres=# \quit // 退出,同 \q
postgres=# \password dlf // 重新设置⽤户dlf的密码,然后需要 \q退出后才⽣效c:\>psql exampledb < user.sql // 将user.sql⽂件导⼊到exampled数据库中postgres=# \h select // 精细显⽰SQL命令中的select命令的使⽤⽅法
postgres=# \l // 显⽰所有数据库
postgres=# \dt // 显⽰当前数据库中的所有表
postgres=# \d [table_name] // 显⽰当前数据库的指定表的表结构关于白露节气的诗
postgres=# \c [database_name] // 切换到指定数据库,相当于use
postgres=# \du // 显⽰所有⽤户
postgres=# \conninfo // 显⽰当前数据库和连接信息
postgres=# \e // 进⼊记事本sql脚本编辑状态(输⼊批命令后关闭将⾃动在命令⾏中执⾏) postgres=# \di // 查看索引(要建⽴关联)
postgres=# \prompt [⽂本] 名称 // 提⽰⽤户设定内部变数
postgres=# \encoding [字元编码名称] // 显⽰或设定⽤户端字元编码
*可以将存储过程写在⽂本⽂件中aaa.sql,然后在psql状态下:
postgres=# \i aaa.sql // 将aaa.sql导⼊(到当前数据库)
postgres=# \df // 查看所有存储过程(函数)
postgres=# \df+ name // 查看某⼀存储过程
postgres=# select version(); // 获取版本信息
postgres=# select usename from pg_user; // 获取系统⽤户信息
postgres=# drop User ⽤户名 // 删除⽤户
其它SQL命令通⽤如(标准化SQL语句):
*创建数据库:
create database [数据库名];
*删除数据库:
drop database [数据库名];
*创建表:
create table ([字段名1] [类型1] ;,[字段名2] [类型2],......;);
*在表中插⼊数据:
insert into 表名 ([字段名m],[字段名n],......) values ([列m的值],[列n的值],......);
*显⽰表内容:
select * from student;
*重命名⼀个表:
alter table [表名A] rename to [表名B];
*删除⼀个表:
drop table [表名];
*在已有的表⾥添加字段:
alter table [表名] add column [字段名] [类型];
*删除表中的字段:
alter table [表名] drop column [字段名];
*重命名⼀个字段:
alter table [表名] rename column [字段名A] to [字段名B];
*给⼀个字段设置缺省值:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。