//author 满晨晨
//time 2009 4 7 上午
数据操作DML
insert
delect
update
数据库对象操作DDL
creat 表 视图 索引 触发器 序列 函数 存储过程 包 包体 用户
alter
drop
DQL数据查询
select
DCL数据控制
user grant
1 身份验证
windows
混合
2 授权
--所有的列
select * from authors
--指定的列
select au_lname ,au_fname,phone from athors
--两列联合
select au_lname+au_fname,phone from athors
--重起名 别名
select au_fname+au_lname 'Name',phone Phone('Phone') from authors
--内容过多 选取前几条
select top 10 au_lname ,au_lfname,phone from authors
--百分之
select top 10 percent au_lname,au_fname,phone from authors
--列出所有书籍的名称和其8.5折以后的价格
select title,price*0.85 as price(重起名) from titles
--where 处理操作数据行 逻辑运算 and or not
比较运算!=, = ,<=, >=
in ,not in
between and ,not between and
--NULL定义它是最小的
--图书价格在5元以下的图书编号,名称,价格
select title_id,title,price
from titles
where price <5
说明有比较时候NULL无法比较,NULL的数据行不显示 遍历时出现NULL跳过
--Order by显示的呈现方式进行排序,对指定的结果集进行排序
asc升序 默认,desc 降序
select title_id ,title,price
from titles
order by price desc
注意哪些数据类型进行排序
通常对多列排序
排序是对结果集的一种排序
select title_id ,title,price
from titles
order by price desc,title_id先对price按降序排列,无法排的再按title_id排序
查找价格的在5元以上的图书名称和价格,并按照价格的降序排序
select title,price
from titles
where price >=5
order bu pricr desc
select title,price
from titles
where price >=5 and price<=15
select userName,userpassort
from
where userName="andsj" and uesrpassort="51365"
select userName,userpassort
from
where userName='andsj ' and uesrpassort=51365 or 1=1
上面两句是不同的or 1=1 是指username userpassort 为任意 取所有
select au_fname,au_lname,phone from authors
where city='aokelan' or city ='bekelan' or city='gary'
或者用in来表示值(数据)的集合
select au_fname,au_lname,phone from authors
where city in ('aokelan','bekelan','gray')
not in 表示都不存在于()数据中
=的时候 数字不用加单引号 字符串需要
is ,is not 用作NULL不能比较情况的处理
select title,price from titles
where price is not null
//price =null 这个是错误的 null是无法和比较符号用的
基础数据
整数
bigint 64 int 32 smallint 16 tinyint 8
小数
decimal numeric 等价
float
real
货币
money
smallmoney
日期时间
datetime
smalldatetime
'2008-12-12 23:54:54.1254'
字符串
char char(30) 最多30个字符
varchar varchar(30)内存可变 最多30个字符 只是你存几个就用几个内存
text 不限制字符大小 主要是用于一篇文档
ASCLL码
nchar
nvarchar
ntext
Uinux码好象是 发音是
二进值数据类型
bit
binary
varbinary
image 图象型储存数据
cursor 游标
table 结果集显示