数据库学习笔记(十)

--声明一个@myvar变量,然后将一个字符串放在变量里,在输出@myvar变量的值
declare @myvar nchar(20) 
set @myvar = 'This is a test'
select @myvar
go




--显示当前的日期和时间为止试图登录SQLserve2005
select GETDATE() AS '当前的时期和时间'
@@CONNECTIONS AS '试图登录的次数'




--通配符和逻辑运算符的LIKE的举例
ALTER TABle student
with NOCHECK ADD CONSTRAINT CK_student_like
check (E-mail like '%@%.[a-z][a-z][a-z]')






--逻辑运算符IN的使用方法
select *
from score
where studentno in('0925111109', '082310007', '0937221508')






--逻辑运算符Between
select *
from score
where final BETWEEN 90 and 99 


--输出函数的值CEILING(), FLOOR(), ROUND()
select CEILING (13.6), floor(13.7), ROUND(13.45767, 3)




--从GETDATE函数返回的日其中提取年份,月份,和天数并输出
select DATENAME(YEAR, GETDATE()) as 'Year Name'
select DATENAME(MONTH, GETDATE()) as 'Month Name'
Select DATENAME(DAY, GETDATE()) as 'Day Name'


--转换函数
PRINT '今天是' + CONVErt(varchar(12), GETDATE(), 101)
PRINT '今年是' + CONvert(varchar(12), YEAR(GETDATE()))
PRINT '本月是' + CONVERt(varchar(12), Month(GETDATE())) + '月'


--字符串函数
DECLARE @string_to_trim varchar(60) 
set @string_to_trim='     FIVE spaces'
select  'Here is the sting ' + LTRIM(@string_to_trim)

你可能感兴趣的:(数据库学习笔记(十))