SQL常用语句一览

SQL常用语句一览

(1)、数据记录筛选:

sql = " select * from 数据表 where 字段名 = 字段值 order by 字段名 [desc] "

sql = " select * from 数据表 where 字段名 like '%字段值%' order by 字段名 [desc] "

sql = " select top10 * from 数据表 where 字段名 order by 字段名 [desc] "

sql =" select * from 数据表 where 字段名 in ('值1', '值2', '值3') "

sql = " select * from 数据表 where 字段名 between 值1 and 值2 "


(2)、更新数据记录:

sql = " update 数据表 set 字段名 = 字段值 where 条件表达式 "

sql = " update 数据表 set 字段1 = 值1,字段2 = 值2…… 字段n = 值n where 条件表达式 "


(3)、删除数据记录:

扫描二维码关注公众号,回复: 3716339 查看本文章

sql = " delete from 数据表 where 条件表达式 "

sql = " delete from 数据表 "     (将数据表所有记录删除)

(4)、添加数据记录:

sql = " insert into 数据表 (字段1, 字段2, 字段3…)  values  (值1, 值2, 值3…) "

sql = " insert into 目标数据表 select * from 源数据表 "    (把源数据表的记录添加到目标数据表)


1. 向表中添加新的字段

   alter  table  table_name  add  column_name  varchar2(20) not null

2. 删除表中的一个字段

    delete table table_name column column_name

3. 修改表中的一个字段名

   alter table table_name rename column oldname to newname

4. 添加主键约束

   alter table 表名

   add constraint 约束名 primary key (列名)

5. 添加唯一约束

   alter table 表名

   add constraint 约束名 unique (列名)

6. 添加默认约束

   alter table 表名

    add constraint 约束名 default(内容) for 列名

7. 添加check约束

   alter table 表名

   add constraint 约束名 check(内容)

8. 添加外键约束

   alter table 表名

   add constraint 约束名 foreign key(列名) references 另一表名(列名)

9. 删除约束

   alter table 表名

   drop constraint 约束名

猜你喜欢

转载自blog.csdn.net/rocling/article/details/82812435
今日推荐