Sql Server2008温故而知新系列11:存储过程
存储过程个人理解就是一段指令的集合,这段指令集里面可以有变量、增删改查语句、流程控制、循环语句等
在SQL SERVER中创建过程的命令create proc[edure] proc_name [参数名1 type],[参数名2 type] as begin ………………end
附个简单的例子:
use myDB
go
create proc p_test
@name varchar(20),
@age smallint 
as 
begin
if exists(select name from tstb where name=@name)
    begin
        update tstb set age = @age where name = @name
    end
else
    begin
        insert into tstb(name,age) values (@name,@age)
    end
select * from tstb where name = @name
end
go
p_test ‘John‘,30上述很简单的过程,修改表中指定人员的年龄;如果指定人员不存在,则表中插入该人员及年龄;
第19,20行;执行过程命令: [execute/exec] procedure_name [参数1],[参数2],[参数N]
exec/execute 也可以直接省略 直接写过程名后加参数;
p_test ‘john‘,30 指定tstb表中的john的年龄为30,如果tstb表中没有john,那么新增John,年龄30;
然后查询tstb表中John的信息。
相关推荐
  明月清风精进不止    2020-01-14  
   liuyang000    2019-12-27  
   dreamhua    2019-12-23  
   herohope    2019-12-17  
   zhaojp0    2019-12-14  
   li00lee    2016-10-21  
   dropkai    2010-04-24  
   zjyzz    2007-08-26  
   姚强    2011-09-06  
   dropkai    2012-08-07  
   yierxiansheng    2012-08-27  
   Omega    2015-01-11  
   huanging    2014-11-23  
   sflsgfs    2014-04-30  
   seegroung    2013-04-04  
   cshpanda    2012-06-04  
 