数据定义语句DDL:
1.创建create:create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
例:CREATE TABLE GAUSSPROJECT.KEY_RISK_INFO (
RISK_ID BINARY_BIGINT NOT NULL AUTO_INCREMENT,
ISSUE_DESC VARCHAR(1000), -- 问题描述
CLOSED_DATE TIMESTAMP, -- 闭环日期
REMARK VARCHAR(2000),
PRIMARY KEY (RISK_ID)
) ;
2.修改alter:
(1)删除列:ALTER TABLE 【表名】 DROP 【列名】
(2)增加列:ALTER TABLE 【表名】 ADD 【列名】 【类型】
例:alter table "meta_common"."product_info" add column "flow_control_level" integer not null default 0;
(3)重命名列:ALTER TABLE 【表名】 CHANGE 【列名】【新名】
(4)修改表字段:alter table 表名称 change 字段名称 字段名称 字段类型 [是否允许非空]。
alter table 表名称 modify 字段名称 字段类型 [是否允许非空]。
3. 删除drop:DROP TABLE <表名> [RESTRICT|CASCADE](两种模式联级和限制,联级全删,限制需没有下属对象)
4. 清除表数据truncate:truncate 表名。(不涉及事务,不删表结构,仅删数据)
数据操作语句DML:
1.插入insert:INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...);
例:INSERT INTO AUTH_MODULE_TRANSFORM (ID, MODULENAME, MODULENUM, MODULETYPE) VALUES(28, '赋能培训', '28', 'a,b,c');
2. 更新update:UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value;
例:UPDATE AUTH_GROUP_TRANSFORM SET GROUPVALUE='104',SHOW='GaussDB Kernel 运维系统游客' WHERE ID=6;
3. 删除delete:DELETE FROM table_name WHERE some_column=some_value;
例:DELETE FROM Websites WHERE name='Facebook' AND country='USA';
数据查询语句DQL:
1.查询select: SELECT column_name,column_name FROM table_name;
2.查询select distinct:SELECT DISTINCT column_name,column_name FROM table_name;(同时作用多列,多列都相同才会排除,distinct可放在函数中)
3. 内连接inner join(交集):SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name=table2.column_name;
例:select COUNT (DISTINCT a.gauss_version) FROM GAUSSPROJECT.PRODUCT_UPGRADE a INNER JOIN (SELECT MAX(UPGRADE_DATE) AS UPGRADE_DATE, INSTANCE_ABBREVIATION FROM GAUSSPROJECT.PRODUCT_UPGRADE GROUP BY INSTANCE_ABBREVIATION) b ON a.INSTANCE_ABBREVIATION = b.INSTANCE_ABBREVIATION AND a.UPGRADE_DATE = b.UPGRADE_DATE;
4. 外连接outer join(并集):SELECT column_name(s) FROM table1 OUTER JOIN table2 ON table1.column_name=table2.column_name;