SQL语法:
在其他的数据库也能用;
DDL--数据定义(greate teble,drop table,alter table)
DML--数据操作语言(select,insert,update,delete);
主键:
生产 GUID 值的方法
1,SQL中用 newid();
默认值设定为newid的话可以自动插入ID
2,c#中 Guid id = Guid.NewGuid();
数据语法:
//=====================================================
创建表
greate teble
//=====================================================
插入数据
insert into person2(name,age) values('xuwei1',38);
//=====================================================
更新数据
update person3 set age=age+20, name='xuwei'
update person3 set name='gao'where age>=50 or age=60
//=====================================================
删除数据
delete from T_name; 清空数据
drop T_name: 删除表
delete from person3 where age <50
//=====================================================
查询数据
select
数据汇总
SQL 聚合函数 : MAX(最大值),MIN(最小值),AVG(平均值)
SUM(和) COUNT(数量)
大于25岁员工的最高工资: SELECT MAX(FSalary) FROM T_Employee
WHERE FAge>25
最低工资和最高工资: SELECT MIN(FSalary),MAX(FSalary) FROM T_Employee
排序order by
select * from person3 order by age ASC 按升序排
select * from person3 order by age DESC,name asc 按降序排
//top 取值范围
select top 3* from person3 order by age ASC
//=====================================================
通配符 LIKE
select * from person3 where name like '_a_'
多字符通配符 %
select * from person3 where name like '%a%'
//=====================================================
空值的查询 is
select *from person3 where name is null;
select *from person3 where name is not null;
//=====================================================
分组 group by
select age ,count(*) from person3 group by age;
分组后信息过滤用having XX>9;