SQL´¥·¢Æ÷Óï·¨²Î¿¼
ת×Ôhttp://www.tzwhx.com/newOperate/Html/3/31/311/16609.html
Óï·¨
CREATE TRIGGER trigger_name
ON { table | view }
[ WITH ENCRYPTION ]
{
{ { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ , ] [ UPDATE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS
[ { IF UPDATE ( column )
[ { AND | OR } UPDATE ( column ) ]
[ n ]
| IF ( COLUMNS_UPDATED ( ) { bitwise_operator } updated_bitmask )
{ comparison_operator } column_bitmask [ n ]
} ]
sql_statement [ n ]
}
}
²ÎÊý
trigger_name
ÊÇ´¥·¢Æ÷µÄÃû³Æ¡£´¥·¢Æ÷Ãû³Æ±ØÐë·ûºÏ±êʶ·û¹æÔò£¬²¢ÇÒÔÚÊý¾Ý¿âÖбØÐëΨһ¡£¿ÉÒÔÑ¡ÔñÊÇ·ñÖ¸¶¨´¥·¢Æ÷ËùÓÐÕßÃû³Æ¡£
Table | view
ÊÇÔÚÆäÉÏÖ´Ðд¥·¢Æ÷µÄ±í»òÊÓͼ£¬ÓÐʱ³ÆΪ´¥·¢Æ÷±í»ò´¥·¢Æ÷ÊÓͼ¡£¿ÉÒÔÑ¡ÔñÊÇ·ñÖ¸¶¨±í»òÊÓͼµÄËùÓÐÕßÃû³Æ¡£
WITH ENCRYPTION
¼ÓÃÜ syscomments ±íÖаüº¬ CREATE TRIGGER Óï¾äÎı¾µÄÌõÄ¿¡£Ê¹Óà WITH ENCRYPTION ¿É·ÀÖ¹½«´¥·¢Æ÷×÷Ϊ SQL Server ¸´ÖƵÄÒ»²¿·Ö·¢²¼¡£
AFTER
Ö¸¶¨´¥·¢Æ÷Ö»ÓÐÔÚ´¥·¢ SQL Óï¾äÖÐÖ¸¶¨µÄËùÓвÙ×÷¶¼Òѳɹ¦Ö´Ðкó²Å¼¤·¢¡£ËùÓеÄÒýÓü¶Áª²Ù×÷ºÍÔ¼Êø¼ì²éÒ²±ØÐë³É¹¦Íê³Éºó£¬²ÅÄÜÖ´Ðд˴¥·¢Æ÷¡£
Èç¹û½öÖ¸¶¨ FOR ¹Ø¼ü×Ö£¬Ôò AFTER ÊÇĬÈÏÉèÖá£
²»ÄÜÔÚÊÓͼÉ϶¨Òå AFTER ´¥·¢Æ÷¡£
INSTEAD OF
Ö¸¶¨Ö´Ðд¥·¢Æ÷¶ø²»ÊÇÖ´Ðд¥·¢ SQL Óï¾ä£¬´Ó¶øÌæ´ú´¥·¢Óï¾äµÄ²Ù×÷¡£
ÔÚ±í»òÊÓͼÉÏ£¬Ã¿¸ö INSERT¡¢UPDATE »ò DELETE Óï¾ä×î¶à¿ÉÒÔ¶¨ÒåÒ»¸ö INSTEAD OF ´¥·¢Æ÷¡£È»¶ø£¬¿ÉÒÔÔÚÿ¸ö¾ßÓÐ INSTEAD OF ´¥·¢Æ÷µÄÊÓͼÉ϶¨ÒåÊÓͼ¡£
INSTEAD OF ´¥·¢Æ÷²»ÄÜÔÚ WITH CHECK OPTION µÄ¿É¸üÐÂÊÓͼÉ϶¨Òå¡£Èç¹ûÏòÖ¸¶¨ÁË WITH CHECK OPTION Ñ¡ÏîµÄ¿É¸üÐÂÊÓͼÌí¼Ó INS
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......
ΪÁË´ó¼Ò¸üÈÝÒ×Àí½âÎÒ¾Ù³öµÄSQLÓï¾ä£¬±¾Îļٶ¨ÒѾ½¨Á¢ÁËÒ»¸öѧÉú³É¼¨¹ÜÀíÊý¾Ý¿â£¬È«ÎľùÒÔѧÉú³É¼¨µÄ¹ÜÀíΪÀýÀ´ÃèÊö¡£
¡¡¡¡1.ÔÚ²éѯ½á¹ûÖÐÏÔʾÁÐÃû£º
¡¡¡¡a.ÓÃas¹Ø¼ü×Ö£ºselect name as 'ÐÕÃû' from students order by age
¡¡¡¡b.Ö±½Ó±íʾ£ºselect name 'ÐÕÃû' from students order by age
¡¡¡¡2.¾«È·²éÕÒ:
¡¡¡¡a.Ó ......
BCPÊÇSQL ServerÖиºÔðµ¼Èëµ¼³öÊý¾ÝµÄÒ»¸öÃüÁîÐй¤¾ß£¬ËüÊÇ»ùÓÚDB-LibraryµÄ£¬²¢ÇÒÄÜÒÔ²¢Ðеķ½Ê½¸ßЧµØµ¼Èëµ¼³ö´óÅúÁ¿µÄÊý¾Ý¡£
/********************************************************
ÀýÈ磺
´Ó±¾µØ·þÎñÆ÷ÖУ¨ÓÐÓû§ÃûºÍÃÜÂ룩µ¼³ötxtÎı¾
EXEC master..xp_cmdshell 'bcp "select * from pubs..authors" queryou ......
SQL ServerÁ¬½ÓÔ¶³ÌÊý¾ÝÔ´µÄ»ù±¾·½·¨ÓÐÏÂÃæÈýÖÖ£º
OPENDATASOURCE: The OPENDATASOURCE function is used to specify connection information for a remote data source by specifying the OLE DB provider and an initialization string. OPENDATASOURCE can be used directly within a SELECT, INSERT, UPDATE, or DELET ......
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER trigger [dbo].[checkExamNo] on [dbo].[student]
for insert,update as
if exists(select examNo from student whe ......