zoukankan      html  css  js  c++  java
  • 创建存储过程、视图、触发器、表、游标

    • 1存储过程
     1 create procedure dbo.Test
     2 (
     3 @BeginDate datetime,
     4 
     5 )
     6 as
     7 begin tran 
     8 select * 
     9 from dbo.Table 
    10 where ColumnDate=@BeginDate
    11 
    12 end
    • 2视图
    1 create view V_Test
    2 as
    3 select 
    4 convert(varchar(20),column1)
    5 from 
    6 dbo.Table
    7 
    8 go
    • 3触发器
     1 create trigger Trg_UpdateTable_Update
     2 on Table
     3 after for Update/insert/delete
     4 as
     5 if Update(column1)
     6 begin 
     7 
     8 Update dbo.Table 
     9 set column2=value 
    10 from dbo.Table a,inserted b
    11 where a.column3=b.column3
    12 
    13 end
    • 4表
    1 create table dbo.Table
    2 (
    3 column varchar(32) Not null primary Key, --主键不为空
    4 column1 varchar(50) null,
    5 column2 varchar(50) null,
    6 ...
    7 )
    • 5游标

     http://www.cnblogs.com/yuan-jun/p/6505083.html

     1 declare @column1 varchar(20),@column2 int
     2 
     3 declare Table cursor 
     4 for 
     5 select Id,Name 
     6 from dbo.Table1 
     7 
     8 Open Table 
     9 Fetch first from Table into @column1,@column2
    10 while @@Fetch_Status=0
    11 
    12 begin
    13 Update Table set Name=@column2 where Id=@column1
    14 Fetch next from Table into @column1,@column2
    15 end
    16 
    17 close Table
    18 deallocate
    立刻行动,坚持不懈,不断学习!
  • 相关阅读:
    orbis 链接 .a的问题
    程序的循环结构
    程序分支控制
    字符类型及常用的函数
    数字数据类型
    基础练习
    了解计算机
    python基础练习
    markdown基本使用
    jupyterhub
  • 原文地址:https://www.cnblogs.com/deng779256146/p/6654021.html
Copyright © 2011-2022 走看看