【postgresql】表操作

创建表 (CREATE TABLE):

CREATE TABLE table_name ( 
    column1 data_type constraint,
    column2 data_type constraint,
 ... );

插入数据 (INSERT INTO):

INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);

查询数据 (SELECT):

SELECT column1, column2, ... FROM table_name WHERE condition;

更新数据 (UPDATE):

UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;

删除数据 (DELETE):

DELETE FROM table_name WHERE condition;

修改表结构 (ALTER TABLE):

添加列: 
ALTER TABLE table_name ADD COLUMN column_name data_type;
删除列: 
ALTER TABLE table_name DROP COLUMN column_name;
修改列的数据类型: 
ALTER TABLE table_name ALTER COLUMN column_name TYPE new_data_type;
重命名列: 
ALTER TABLE table_name RENAME COLUMN old_column_name TO new_column_name;

重命名表 (RENAME):

ALTER TABLE old_table_name RENAME TO new_table_name;

删除表 (DROP TABLE):

DROP TABLE table_name;

创建索引 (CREATE INDEX):

CREATE INDEX index_name ON table_name (column_name);

删除索引 (DROP INDEX):

DROP INDEX index_name;

创建视图 (CREATE VIEW):

CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition;

删除视图 (DROP VIEW):

DROP VIEW view_name;




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值