sql server 笔记

insert into barcode_1(no1,no2)values(100,600)
select * from barcode_1
update barcode_1 set no1=0,no2=1
select * from barcode_1
delete barcode_1
select * from barcode_1
-----------------------------------------------------------------------------------------
-- 返回TRUE或false控制
if exists (select * from barcode_1 where no1=2) --查询有没有这个条件的返回TRUE或false
begin
--true执行语句
select * from barcode_1 where NO1=2
print '这是第一层'
end
else
begin
--false执行语句
print '没有找到'
update barcode_1 set no1=2
end
--------------------------------------------------------------------------------------
--控制条件控制
declare @test int,@te int   --定义变量
set @te=88                 --付值变量
select @test=no1 from barcode_1 where @te=id  --查询并付值
if @test<10                                 --条件控制
begin
print '成立:'+cast(@test as varchar(20))
end else
begin
print '这个字段是:'+cast(@test as varchar(20)) --字符强制转换
print @test
end

declare @test int   --定义变量
select @test='10000'
print ''+cast(@test as varchar(20))
print @@spid
-------------------------------------------------------------------------------------
--创建一个存储过程
create proc barcode1 @test char(15)
as
begin
print '100000000000'
select * from barcode_1
end
--------------------------------------------------------------------------------------
sp_helptext barcode1 --显示存储写法
---------------------------------------------------------------------------------------
barcode1 '5555555'  --执行存储过程,存储名+存储需要的参数
---------------------------------------------------------------------------------------
--实例存储过程
create proc barcode_3
as
begin
if exists (select * from barcode_1 where no1=2) --查询有没有这个条件的返回TRUE或false
begin
--true执行语句
--select * from barcode_1 where NO1=2
print '这是第一层'
end
else
begin
--false执行语句
print '没有找到'
update barcode_1 set no1=2
end
end
--执行实例
barcode_3
------------------------------------------------------------------------------------
--修改存储过程
alter procedure barcode1 @test char(15)=null  --修改存储过程关键字ALTER
as
begin
 if @test is null
begin
print '没有输入参数!'
end else

select * from barcode_1
end
--执行修改过的存储
barcode1
barcode_3
-----------------
--带参数传递
barcode1 dd

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

那小x的传说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值