数据库的语法

发布 2021-05-11 06:51:28 阅读 1469

添加列:alter table table_name

add column_name column_properties;

查询表结构:desc table_name; 新建—窗口—命令窗口。

删除列:alter table table_name

drop column column_name;

修改列属性:alter table table_name

modify column_name column_properties;

删除表:drop table table_name;

添加数据:insert into table_name (column1,column2...values(value1,value2...

修改表时添加非空约束alter table table_name

modify column_name [constraint constraint_name] not null;

修改表时添加主键约束:alter table table_name

add [constraint constraint_name] primary key (column_name);

修改表时添加检查性约束:alter table table_name

add [constraint constriant_name] check(expression);

修改表时添加唯一约束:alter table table_name

add [constraint constraint_name] unique(column_name);

修改表时添加默认约束:alter table table_name

modify column_name default(default_value);

修改表时添加外键约束:alter table table_name

add [condition condition_name] foreign key(column_name)references

table_name

删除约束语法:alter table table_name

drop constraint constraint_name;

检索(查询)语法:select select_list from table_name where condition_expression

加别名:select name1,stock [as]……

取括号任意一个值:where column_name in(value1,value2...

在两者之间:where column_name between...and...

模糊查询:where column_name like’…’

is null用法:where column_name is null

返回表中的行数:select count(*)column_name…….

去掉完全重复的记录:select distinct column_name…….

自然连接(内连接):select select_list from table1 join table2 on

做降序或升序排序:select select_list from table_name where condition order by colunm_name

asc/desc]

左外连接:select select_list from table1 left join table2 on

右外连接:select select_list from table1 right join table2 on

全外连接:select select_list from table1 full join table2 on

自连接:select distinct select_list from table1 a join table1 b on and <>

嵌套:select select_list from table_name where column_name in(select column_name from table_name where condition)

查询结果创建成新表:create table table_name

asselect select_list from table_name where condition

测试条件是否存在:select select_list from table_name where exists(select select_list from

table_name where condition);

group by分组:select column1,集合函数(column2) from table_name [where condition] group by

column1[order by column_name]

h**ing:select select_list from table_name where codition group by column h**ing condition

[order by column]

集合操作符:select columun_name1,……from…….

集合操作符(union、union all、intersert、minus)

select columun_name2,……from…….

序列语法:create sequence sequence_name

increment by n] 递增值。

start with n] 起始值。

maxvalue] 最大值。

minvalue] 最小值。

cache cache_value] 缓冲。

cycle] 循环。

获取值:sequence_

更新数据update语法:update table_name set column_name=new_value[,column_name2=

new_value2…..where condition

删除delete:delete from table_name[where condition]

删除truncate:truncate table table_name

创建保存点:s**epoint s**epoint_name

回滚:rollback to s**epoint_name

提交事务:commit

创建索引:create [unique]index index_name on table_name(column_name[asc/desc]

删除索引:drop index index_name

视图创建:create [or replace][force|noforce] view view_name[(column_name,….

asselect_statement;

删除视图:drop view view_name;

pl/sql结构:declare]

声明部分);

begin执行部分);

exception、

执行异常部分);

end;pl/sql输出语句:dbms_

声明变量:variable_name data_type:=value;

variable_name date_type default value;

while..loop:while expression loop statement;

end loop;

for..loop:for i in [reverse] lb..hb loop statements;

end loop;

case..when: case expression

when expression_value1 then statements;

when expression_value2 then statements;

else statements;]

end case;

if..else:if expression1 then statement_a;

elsif expression2 then statement_b;

elsif expression3 then statement_c;

else statement_n;

数据库的高级语法

变量定义和赋值。全局变量 只读,由系统维护,作用域是单个连接。常见全局变量。error 返回执行的上一个语句的错误号,如果出错,错误号是大于0的整数,不出错则为0 print error select fro stuinfo print error select from stuinfo print...

数据库操作语法

语法 insert into 表名 列名 values 列值 例 insert into strdents 姓名,性别,出生日期 values 开心朋朋 男 1980 6 15 注意 into可以省略 列名列值用逗号分开 列值用单引号因上 如果省略表名,将依次插入所有列。语法 insert into...

数据库 altertable语法

一 修改表 增加,删除,修改类型 1 如需在表中添加列,请使用下列语法 alter table add datatype 2 要删除表中的列,请使用下列语法 alter table drop column 某些数据库系统不允许这种在数据库表中删除列的方式 drop column column nam...