zoukankan      html  css  js  c++  java
  • sql server 常用

    代码
    --事务
    SET TRANSACTION ISOLATION LEVEL REPEATABLE READ   
    begin transaction
      
    --insert delete update select
      if @@error<>0   
        
    begin
          
    rollback transaction
        
    end
    commit transaction

    --变量
    declare @name varchar(20--声明   
    select @name='zhangsan' --赋值

    --存储过程
    Create proc sp_demo @param1 char(10),@param2 varchar(20),@param3 varchar(20),@param4 int output
    with encryption --加密
    as
    insert table1 (column1,column2,column3)
    Values(@param1,@param2,@param3)
    select @param4=sum(moneyfrom bankMoney where userID='Zhangsan'
    go

    declare @total_price int
    exec insert_bank '004','Zhangsan','',@total_price output
    print '总余额为'+convert(varchar,@total_price)
    go
     
    --视图,视图也是表,一般是多个表的交集
    CREATE VIEW PartitionedView 
    AS
    SELECT * 
    FROM MyDatabase.dbo.PartitionTable1
    UNION ALL
    SELECT *
    FROM Server2.MyDatabase.dbo.PartitionTable2
    UNION ALL
    SELECT *
    FROM Server3.MyDatabase.dbo.PartitionTable3

    --触发器
    Create Trigger tg_event On event
    for Insert 
    As
    begin
      
    insert event_temp (id,project_id,taji_id,[time],event_type,event_miaoshu,drive_id) 
      
    select id,project_id,taji_id,[time],event_type,event_miaoshu,drive_id
      
    from inserted
    end 
  • 相关阅读:
    poj1228 Grandpa's Estate
    poj1113 Wall
    poj2826 An Easy Problem?!
    poj1269 Intersecting Lines
    poj3304 Segments
    BZOJ3832Rally题解
    BZOJ2802Warehouse Store题解
    李超树详解
    BZOJ4241历史研究题解
    洛谷2050 BZOJ2897美食节题解
  • 原文地址:https://www.cnblogs.com/bloodofhero/p/1733412.html
Copyright © 2011-2022 走看看