posts - 1,comments - 0,trackbacks - 0
    常用函数
数学函数
select ABS(-9)
select CEILING(9.00001)
select FLOOR(9.9)
select PI()
select POWER(2,3)
select SORT(9)
select SIGN(0)
select ROUND(892.35,1,7)
select ROUND(892.35,1,0)
select 1+FLOOR(LOG10(48901))
select FLOOR(RAND()*10)

字符串函数
select LEFT('aaaaaa',2)
select RIGHT('123456',2)
select LEN('1')
select LOWER('aaBN')
select UPPER('aaBN')
select rtrim(LTRIM('aaa'))+'**'-trim().Itrim()
select SUBSTRING('abcdefg',2,3)
select REPLACE('aba','a','ccc')
select STUFF('aaaaa',1,2,'bbbbbb')

日期时间
select GETDATE()
select YEAR(GETDATE())
select MONTH(GETDATE())
select DAY(GETDATE())
select DATEADD(mm,100,'1990-10-10')
select DATEDIFF(yy,'1988-8-8',getdate())
查询老师的年龄
select teacher_name , DATEDIFF(yy,出生日期,getdate())
from dbo.teacher

转换函数
select cast('666' as int )+100
select convert(varchar(13),999)+'***'

insert into用法
1.向教师表中加入一个记录,字段的顺序与数目和表中的一样
insert into teacher values()
2.字段的数目与顺序自己指定
insert into teacher(name , sex_id) values('张三',1)
3.从select检索中插入成批记录
insert into dbo.student
select teacher
from dbo.teacher
delete from dbo.student ming like'张%'

update用法
1.更新一个字段
Update teacher
set teacher_name='里斯'
where teacher_id=2
2.教师的基本工资上调5%
Update teacjer
set 基本工资=基本工资*(1.05)
3.多字段更新,每一个用,隔开
Update teacher
set teacher_name='李四' ,
teacjer_id = 1
where teacher_id=3

























posted on 2010-04-09 10:57 zZ的家伙 阅读(116) 评论(0)  编辑  收藏 所属分类: sql语句

只有注册用户登录后才能发表评论。


网站导航: