现在的位置: 首页 > 数据库 > 正文

【黑马程序员】C#之SQL

2019年09月07日 数据库 ⁄ 共 1120字 ⁄ 字号 评论关闭

----------------------
ASP.Net+Android+IOS开发
.Net培训、期待与您交流! --------------------

一、SQL基础
1、创建数据库
creat database 数据库名称
2、删除数据库
drop database 数据库名称
3、创建新表
crete table 表名
4、根据已有的表创建新表
create table 新 like 旧
5、添加主键
Alter table 表名 add primary key(col)
6、删除主键
Alter table 表名 drop primary key(col)
7、创建索引
create [unique] index idxname on tabname(col..)
8、删除索引
drop index idxnme
二、SQL基础语句
1、选择:select * from table where
2、插入:insert into table(col1,col2..)values(value1,value2...)
3、删除:delete from table where
4、更新:update table set col1=value1 where 条件
5、超找:select * from tablewhere col1 like "%value1%" like
6、排序:select * from table order by col1 [desc]
7、总数:select count * as totalcount from table
8、求和:select sum(col1) as sumvalue from table
9、平均:slect avg(col1) as avgvalue from table
10、最大:select max(col1) as maxvalue from table
11、最小:select min(col1) as minvalue from table

三、运算符
union 运算符:
union运算符通过组合其它两个结果表并消去表中任何重复行而派生出一个结果表。当ALL与union一起使用,则不消除重复行
except运算符:
EXCEPT 运算符通过包括所有在 TABLE1 中但不在 TABLE2 中的行并消除所有重复行而派生出一个结果表。当 ALL 随 EXCEPT 一起使用时 (EXCEPT ALL),不消除重复行。
INTERSECT 运算符:
INTERSECT 运算符通过只包括 TABLE1 和 TABLE2 中都有的行并消除所有重复行而派生出一个结果表。当 ALL 随 INTERSECT 一起使用时 (INTERSECT ALL),不消除重复行。

------------------------
ASP.Net+Android+IOS开发
.Net培训、期待与您交流! ----------------------

抱歉!评论已关闭.