---------------------- Windows Phone 7手机开发、Net培训、期待与您交流! ----------------------
Database 数据库
DBMS(Database Management System,数据库管理系统)和数据库。
不同的DBMS有自己的不同特点:MYSQL、MSSQLServer、DB2、Oracle、Access、Sybade等。
大部分数据库都需要数据库服务器,除Acess、SQLServerCE等文件型数据库之外。
Catalog(分类)(又叫数据库DataBase、表空间TableSpace),不同类的数据应放到不同的数据库中。
好处:便于对各个Catalog个性化管理
避免命名冲突
安全性更高
Table(表)
Row(行)
Column(列)
Field(字段)
主键是数据行的唯一标识。不重复的列才能当主键。一个表没主键很难处理,所以没特殊理由都要有主键。
主键:业务主键(有业务意义,如身份证),逻辑主键(没业务意义,给程序看,业务人员不看,推荐用)。
varchar、nvarchar和char(n)的区别:char(n)不足长度n的部分用空格填充。
SQL语句中字符串用单引号
DDL(数据定义语言)如:create table 、drop table、alter table
DML(数据操作语言)如:select、insert、update、delete
创建表
create table 表名
(
字段名 类型,
...
...
)
删除表
drop table 表名
插入数据
insert into 表名(字段名1、字段名2、.......) values(值1、值2、......)
删除数据
delete from 表名
Int自增长字段优点:占用空间小、无需开发人员干预、易读。缺点:效率低:数据导入导出很痛苦
Guid(业界主流)优点:效率高、数据导入导出方便。缺点:占用空间大、不易读。sql中用NewId()
.net中用GuId.NewGuId()生成Guid
更新数据
update 表名 set 字段名=xx
查询数据
select * from 表名 where 条件
select 字段名1,字段名2 表名 where 条件
as 给字段取一个别名
select 字段名 as 别名 from 表名
聚合函数 count (统计)、 max(最大)、 min(最小)、 avg(平均)、 sum(和)
排序 order by
order by 字段 asc(升序)[desc(降序)]
有2个排序条件用逗号且按条件的先后排序:
order by 字段 asc,字段 desc
通配符 _(单字),%(0或多个)。过滤通配符用 like
select * from 表名 like '_xxx'
select * from 表名 like '%xxx'
null 不知道
select null+1 结果为null
select * from 表名 where 字段 is null
单值判断,相当于switch case
case expression
when value1 then returnvalue1
when value2 then returnvalue2
when value3 then returnvalue3
else defaultreturnvalue
end
删除重复的行 distinct
联合结果集 union(想不去掉重复行,用union all)
基本原则 :每个结果集必须有相同的列数,且列类型必须相容
数字函数
abs()绝对值
ceiling()舍入到最大整数
floor()舍入到最小整数
round()四舍五入
字符串函数
len()字符串长度
lower() upper()转大写 小写
ltrim()rtrim()去掉左侧空格 右侧 空格
substring(string,start_postion,length)截取字符串
日期函数
getdate()获取当前日期
dateadd(datepart,number,date)计算增加后日期
datediff(datepart,startdate,endstart)计算日期只差
datepart(datepart,date)返回日期指定部分
类型转换函数
cast(expression as date_type)
convert(date_type,expression)
空值处理 isnull(expression,value) expression不为空返回expression,为空返回value。
---------------------- Windows Phone 7手机开发、Net培训、期待与您交流! ----------------------
详细请查看: http://net.itheima.com