自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

SQL Server觸發(fā)器之圖形化操作

數(shù)據(jù)庫 SQL Server
以下的文章是通過圖形化操作SQL Server觸發(fā)器的相關(guān)操作步驟描述來剖析圖形化操作SQL Server觸發(fā)器的基本應(yīng)用原理,以下就是相關(guān)內(nèi)容的詳細(xì)介紹。

以下的文章主要向大家講述的是圖形化操作SQL Server觸發(fā)器的實際應(yīng)用,如果你在圖形化操作SQL Server觸發(fā)器的實際應(yīng)用中存在不解之處時,你不妨瀏覽下面的文章,希望你能從中獲得自己想要的東西。

查看觸發(fā)器情況

 

圖形化操作結(jié)合T-SQL命令

(1)sp_helptrigger 觸發(fā)器名

查看觸發(fā)器的名稱,擁有者和五個布爾值

supdate,isdelete,isinsert,isafter,isinsteadof

(2)sp_helptext 觸發(fā)器名

查看文本信息

(3)設(shè)置某一SQL Server觸發(fā)器的無效和重新有效

無效: use northwind alter table 表名 disable trigger 觸發(fā)器名 重新有效: use northwind alter table 表名 enable trigger 觸發(fā)器名

(4)刪除觸發(fā)器

use northwind drop trigger 觸發(fā)器名,觸發(fā)器名

作業(yè)3:

在order_test表上建立一個插入SQL Server觸發(fā)器,在添加一個訂單時,減少cust_test表的相應(yīng)貨物的記錄的庫存量。

作業(yè)4:

在order_test表上建立一個插入觸發(fā)器,規(guī)定訂單日期(Odate)不能手工修改。

作業(yè)5:

要求訂購的物品一定要在倉庫中有的,并且數(shù)量足夠。

例6:

在order_test表上建立一個插入觸發(fā)器,同時插入多行數(shù)據(jù)時,要求訂購的物品一定要在倉庫中有的。

答案3:

use northwind go create trigger cust_orders_ins3 on order_test after insert as update cust_test set cstorage=cstorage-inserted.orders from cust_test,inserted where cust_test.customerid=inserted.customerid

答案4:

use northwind go create trigger orderdateupdate on order_test after update as if update (odate) begin raiserror('Error',10,1) rollback transaction end

答案5:

use northwind go create trigger order_insert5 on order_test after insert as begin if(select count(*) from cust_test,inserted where cust_test.customerid=inserted.customerid)=0 begin print 'No entry in goods for your order' rollback transaction end if(select cust_test.cstorage from cust_test,inserted where cust_test.customerid=inserted.customerid)< (select inserted.orders from cust_test,inserted where cust_test.customerid=inserted.customerid) begin print 'No enough entry in goods for your order' rollback transaction end end

答案6:

use northwind go create trigger order_insert6 on order_test after insert as if (select count(*) from cust_test,inserted where cust_test.customerid=inserted.customerid)<>@@rowcount --可以在觸發(fā)器邏輯中使用 @@ROWCOUNT 函數(shù)以區(qū)分單行插入和多行插入。 begin delete order_test from order_test,inserted where order_test.orderid=inserted.orderid and inserted.customerid not in (select customerid from cust_test) end print @@rowcount

Transact-SQL 參考

 

  1. SET ROWCOUNT 

使 Microsoft? SQL Server? 在返回指定的行數(shù)之后停止處理查詢。

語法

 

  1. SET ROWCOUNT { number | @number_var } 

參數(shù)

 

  1. number | @number_var 

是在停止給定查詢之前要處理的行數(shù)(整數(shù))。

注釋

建議將當(dāng)前使用 SET ROWCOUNT 的 DELETE、INSERT 和 UPDATE 語句重新編寫為使用 TOP 語法。有關(guān)更多信息,請參見 DELETE、INSERT 或 UPDATE。

對于在遠(yuǎn)程表和本地及遠(yuǎn)程分區(qū)視圖上執(zhí)行的 INSERT、UPDATE 和 DELETE 語句,忽略 SET ROWCOUNT 選項設(shè)置。

若要關(guān)閉該選項(以便返回所有的行),請將 SET ROWCOUNT 指定為 0。

說明 設(shè)置 SET ROWCOUNT 選項將使大多數(shù) Transact-SQL 語句在已受指定數(shù)目的行影響后停止處理。這包括觸發(fā)器和 INSERT、UPDATE 及 DELETE 等數(shù)據(jù)修改語句。ROWCOUNT 選項對動態(tài)游標(biāo)無效,但限制鍵集的行集和不感知游標(biāo)。使用該選項時應(yīng)謹(jǐn)慎,它主要與 SELECT 語句一起使用。

如果行數(shù)的值較小,則 SET ROWCOUNT 替代 SELECT 語句 TOP 關(guān)鍵字。

SET ROWCOUNT 的設(shè)置是在執(zhí)行或運(yùn)行時設(shè)置,而不是在分析時設(shè)置。

權(quán)限

SET ROWCOUNT 權(quán)限默認(rèn)授予所有用戶。

示例

SET ROWCOUNT 在指定的行數(shù)后停止處理。在下例中,注意有 x 行滿足預(yù)付款少于或等于  $5,000 的條件;但是,從更新所返回的行數(shù)中可以看出并非所有的行都得到處理。ROWCOUNT 影響所有的 Transact-SQL 語句。

 

  1. USE pubs GO SELECT count(*) AS Cnt FROM titles WHERE advance >= 5000 GO 

下面是結(jié)果集:

Cnt ----------- 11 (1 row(s) affected) 現(xiàn)在,將 ROWCOUNT 設(shè)置為 4,并更新預(yù)付款等于或大于  $5,000 的所有行。

  1. SET ROWCOUNT to 4. SET ROWCOUNT 4 GO UPDATE titles SET advance = 5000 WHERE advance >= 5000 GO 

以上的相關(guān)內(nèi)容就是對圖形化操作SQL Server觸發(fā)器的介紹,望你能有所收獲。 

【編輯推薦】

  1. SQL Server備份文件中對現(xiàn)存數(shù)據(jù)庫的導(dǎo)入
  2. SQL Server 2000重建索引的實際操作流程
  3. 改善SQL Server安全規(guī)劃的6步驟
  4. SQL Server 2000文件損壞的修復(fù)方案
  5. SQL Server2000安裝中的提示掛起的解決

 

責(zé)任編輯:佚名 來源: 比特網(wǎng)
相關(guān)推薦

2010-09-13 17:03:34

sql server觸

2009-04-07 13:56:03

SQL Server觸發(fā)器實例

2010-10-20 14:34:48

SQL Server觸

2010-10-22 11:10:43

SQL Server觸

2010-11-08 11:49:24

SQL Server管

2010-07-16 10:19:31

2010-11-12 15:35:55

SQL Server約

2010-07-06 14:47:03

SQL Server數(shù)

2010-11-10 13:37:01

SQL Server觸

2011-03-28 10:05:57

sql觸發(fā)器代碼

2011-03-03 09:30:24

downmoonsql登錄觸發(fā)器

2009-06-27 18:35:00

LinuxNFS圖形化

2010-07-19 09:50:58

SQL Server2

2010-04-19 10:43:27

SQL Server

2010-10-19 15:31:40

sql server觸

2019-10-22 07:50:45

SqlServer數(shù)據(jù)庫觸發(fā)器

2010-07-05 11:01:37

Sql Server觸

2010-04-15 15:32:59

Oracle操作日志

2010-09-01 16:40:00

SQL刪除觸發(fā)器

2010-06-30 09:36:25

SQL Server
點贊
收藏

51CTO技術(shù)棧公眾號