代碼
--事務
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(money) from 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