2014-5-13-sql 查询指定表是否含有指定列

1.正常插入

if not exists(

select   1   from   syscolumns   where   id=object_id('source_wait')   and   name='sort'  )
begin
alter table source_wait add  sort  int not null default 0
end
go


2.标示插入

set IDENTITY_INSERT 表名 on
set IDENTITY_INSERT 表名 off



3.新增存储过程,首先判断存储过程是否存在

---获取短信平台用户信息
---zy 
---2014-07-08
if exists(select * from dbo.sysobjects 
where id=object_id('dbo.p_q_user_getuserinfobysid') and objectproperty(id,'isprocedure')=1)
begin
drop procedure p_q_user_getuserinfobysid
end
go


create proc [dbo].[p_q_user_getuserinfobysid]
@sid int
as
begin
select
top 1
a.uid,a.uname,a.upwd,a.isactive,a.apptime,b.ruletypeid,b.limitamount,b.starttime,b.endtime,b.ruletypename,b.id
,a.sid,row_number() over (order by uid desc) as row
from
t_users a 
outer apply
(
select 
top 1 t1.id,t1.ruletypeid,t1.limitamount,t1.starttime,t1.endtime,t2.ruletypename
from 
t_smsrules t1
left join 
t_smsruletype t2 on t1.ruletypeid=t2.ruletypeid
where 
t1.uid=a.uid
) b
where
a.sid =@sid
and
a.isdel = 0
and 
a.isactive=1
order by apptime desc
end
go




你可能感兴趣的:(2014-5-13-sql 查询指定表是否含有指定列)