码迷,mamicode.com
首页 > 数据库 > 详细

sql建表,建sp

时间:2017-01-18 15:00:03      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:constrain   var   iss   test   nvarchar   tab   nbsp   isnull   lease   

举个栗子

 

if object_id(N‘[dbo].[TestForekoy_Mission]‘,N‘u‘) is not null
    drop table [dbo].[TestForekoy_Mission]
go
create table [dbo].[TestForekoy_Mission]
(
    [Mno]          int     identity(100001,1)     not null  primary key,
    [Mname]        nvarchar(20)      not null,
    [Detail]       nvarchar(500),
    [DateRelease]  date,
    [State]        nvarchar(20)     
)
go
alter table [dbo].[TestForekoy_Mission] add constraint DF_TestForekoy_Mission_DateRelease default (GetDate()) for [DateRelease]
go
alter table [dbo].[TestForekoy_Mission] add constraint DF_TestForekoy_Mission_State default ‘未进行‘ for [State]
go

 

if object_id(N‘[dbo].[TestForekoy_uspMission_Add]‘,N‘p‘) is not null
    drop procedure [dbo].[TestForekoy_uspMission_Add]
go
create procedure [dbo].[TestForekoy_uspMission_Add]
    @Mname        nvarchar(20),
    @Detail       nvarchar(500),
    @DateRelease  date,
    @State        nvarchar(20)
as
begin
    set nocount on
    insert into [dbo].[TestForekoy_Mission]
    values(@Mname,@Detail,@DateRelease,@State)
    set nocount off
end
go
grant execute on [dbo].[TestForekoy_uspMission_Add] to [db_spexecute],[siteuser]
go

 

if object_id(N‘[dbo].[TestForekoy_uspStaffSecurity_Update]‘,N‘p‘) is not null
    drop procedure [dbo].[TestForekoy_uspStaffSecurity_Update]
go
create procedure [dbo].[TestForekoy_uspStaffSecurity_Update]
    @Sno        int          =null,
    @Password   varchar(20)  =null,
    @Question   nvarchar(50) =null,
    @Answer     nvarchar(50) =null,
 @InputWrong int          =null
as
begin
    set nocount on
    update [dbo].[TestForekoy_StaffSecurity]
    set [Password] = isnull(@Password,[Password]),
        [Question] = isnull(@Question,[Question]),
        [Answer]   = isnull(@Answer,[Answer]),
  InputWrong = isnull(@InputWrong,InputWrong)
    where [Sno]=@Sno
    set nocount off
end
go
grant execute on [dbo].[TestForekoy_uspStaffSecurity_Update] to [db_spexecute],[siteuser]
go

sql建表,建sp

标签:constrain   var   iss   test   nvarchar   tab   nbsp   isnull   lease   

原文地址:http://www.cnblogs.com/forekoy/p/6296669.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!