Sql练习15题

--1.从boxbarcode表中,查询goodsname包含“[”的记录,写出2种查询方式。
select * from BoxBarcode where goodsname like '%[[]%'
select * from BoxBarcode where goodsname like '%/[%' escape '/'
--2.从travelspot表中,查询spot_intr中不包含spot_name的记录,写出2种查询方式。 
select * from travelspot where spot_intr not like '%'+spot_name+'%'
select * from travelspot where CHARINDEX(spot_name,spot_intr) = 0
select * from travelspot where PATINDEX('%'+spot_name+'%',spot_intr)=0
--3.建立一张表travelspot2,它的结构与内容与travelspot完全相同。
select * into travelspot2 from travelspot
--4.从boxbarcode表中,随机查询10条记录。
select top 10 * from BoxBarcode order by newid()
--5.判断数据表“users”是否存在,若存在输出“exists”,否则输出“noexists”
if((select name from sys.objects where name = 'users' and type = 'U')is null)
print 'noexists'
else
print 'exists'


if(OBJECT_ID('users','U') is null)
print 'noexists'
else
print 'exists'
--6.查询logistics表中以“recipient”字段正序排列的第6条至第10条记录。
select * from (select *,ROW_NUMBER() over(order by recipient) as num from logistics) as t where num between 6 and 10
--7.将数据表“order_201501” 与 “order_201502”表中的数据合并在一起显示。
select * from order_201501 union select * from order_201502
--8.备份数据库“SmallDemo”到“D:\backup.bak”
backup database SmallDemo to disk = 'D:\backup.bak'
--9.获取基于当前时间加上10天的日期。
select DATEADD(day,10,getdate())
--10.将int 类型的 100转换为字符类型,写出3种方式。
select CONVERT(varchar(3),100)
select CAST(100 as varchar(3))
select rtrim(LTRIM(str(100)))
--11.对score表中的所有记录添加一列行号后输出。
select *,ROW_NUMBER() over(order by ids) as num from Score
--12.建立一个加密视图(view_users_list),返回users表中的全部记录。
create view view_users_list with encryption
as
select * from users
--13.取0-300之间的随机数,且随机数不能等于100,200
declare @i int


set @i = 300*RAND()


while (@i = 100 or @i =200)
begin
set @i = 300*RAND()
end


print @i
--14.查看数据库中所有的触发器。
select * from sys.objects where type = 'TR'
--15.判断users表中的userid列中的数据是否为数字类型,若为数字类型,输出Yes,否则输出No
select *,case when ISNUMERIC(userid)=0 then 'No' else 'Yes' end from users

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值