SQL Server´¥·¢Æ÷´´½¨¡¢É¾³ý¡¢Ð޸ġ¢²é¿´Ê¾Àý½Ì³Ì
Ò»﹕
´¥·¢Æ÷ÊÇÒ»ÖÖÌØÊâµÄ´æ´¢¹ý³Ì﹐Ëü²»Äܱ»ÏÔʽµØµ÷ÓÃ﹐¶øÊÇÔÚÍù±íÖвåÈë¼Ç¼﹑¸üмǼ»òÕßɾ³ý¼Ç¼ʱ±»×Ô¶¯µØ¼¤»î¡£ËùÒÔ´¥·¢Æ÷¿ÉÒÔÓÃÀ´ÊµÏÖ¶Ô±íʵʩ¸´ÔÓµÄÍê
ÕûÐÔÔ¼`Êø¡£
¶þ﹕ SQL
ServerΪÿ¸ö´¥·¢Æ÷¶¼´´½¨ÁËÁ½¸öרÓñí﹕Inserted±íºÍDeleted±í¡£ÕâÁ½¸ö±íÓÉϵͳÀ´Î¬»¤﹐ËüÃÇ´æÔÚÓÚÄÚ´æÖжø²»ÊÇÔÚÊý¾Ý¿âÖС£ÕâÁ½¸ö
±íµÄ½á¹¹×ÜÊÇÓë±»¸Ã´¥·¢Æ÷×÷ÓõıíµÄ½á¹¹Ïàͬ¡£´¥·¢Æ÷Ö´ÐÐ Íê³Éºó﹐Óë¸Ã´¥·¢Æ÷Ïà¹ØµÄÕâÁ½¸ö±íÒ²±»É¾³ý¡£
Deleted±í´æ·ÅÓÉÓÚÖ´ÐÐDelete»òUpdateÓï¾ä¶øÒª´Ó±íÖÐɾ³ýµÄËùÓÐÐС£
Inserted±í´æ·ÅÓÉÓÚÖ´ÐÐInsert»òUpdateÓï¾ä¶øÒªÏò±íÖвåÈëµÄËùÓÐÐС£
Èý﹕Instead of ºÍ After´¥·¢Æ÷
SQL Server2000ÌṩÁËÁ½ÖÖ´¥·¢Æ÷﹕Instead of ºÍAfter ´¥·¢Æ÷¡£ÕâÁ½ÖÖ´¥·¢Æ÷µÄ²î±ðÔÚÓÚËûÃDZ»¼¤»îµÄͬ﹕
Instead of´¥·¢Æ÷ÓÃÓÚÌæ´úÒýÆð´¥·¢Æ÷Ö´ÐеÄT-SQLÓï¾ä¡£³ý±íÖ®Íâ﹐Instead of
´¥·¢Æ÷Ò²¿ÉÒÔÓÃÓÚÊÓͼ﹐ÓÃÀ´À©Õ¹ÊÓͼ¿ÉÒÔÖ§³ÖµÄ¸üвÙ×÷¡£
After´¥·¢Æ÷ÔÚÒ»¸öInsert,Update»òDeletedÓï¾äÖ®ºóÖ´ÐÐ﹐½øÐÐÔ¼Êø¼ì²éµÈ¶¯×÷¶¼ÔÚAfter´¥·¢Æ÷±»¼¤»î֮ǰ·¢Éú¡£After´¥
·¢Æ÷Ö»ÄÜÓÃÓÚ±í¡£
Ò»¸ö±í»òÊÓͼµÄÿһ¸öÐ޸Ķ¯×÷(insert,updateºÍdelete)¶¼¿ÉÒÔÓÐÒ»¸öinstead of
´¥·¢Æ÷﹐Ò»¸ö±íµÄÿ¸öÐ޸Ķ¯×÷¶¼¿ÉÒÔÓжà¸öAfter´¥·¢Æ÷¡£
ËÄ﹕´¥·¢Æ÷µÄÖ´Ðйý³Ì
Èç¹ûÒ»¸öInsert﹑update»òÕßdeleteÓï¾äÎ¥·´ÁËÔ¼Êø﹐ÄÇçÛAfter´¥·¢Æ÷²»»áÖ´ÐÐ﹐ÒòΪ¶ÔÔ¼ÊøµÄ¼ì²éÊÇÔÚAfter´¥·¢Æ÷±»¼¤¶¯Ö®Ç°·¢
ÉúµÄ¡£ËùÒÔAfter´¥·¢Æ÷²»Äܳ¬Ô½Ô¼Êø¡£
Instead of
´¥·¢Æ÷¿ÉÒÔÈ¡´ú¼¤·¢ËüµÄ²Ù×÷À´Ö´ÐС£ËüÔÚInserted±íºÍDeleted±í¸Õ¸Õ½¨Á¢﹐ÆäËüÈκβÙ×÷»¹Ã»Óз¢Éúʱ±»Ö´ÐС£ÒòΪInstead of
´¥·¢Æ÷ÔÚÔ¼Êø֮ǰִÐÐ﹐ËùÒÔËü¿ÉÒÔ¶ÔÔ¼Êø½øÐÐһЩԤ´¦Àí¡£
Îå﹕ʹÓÃT-SQLÓï¾äÀ´´´½¨´¥·¢Æ÷
»ù±¾Óï¾äÈçÏÂ﹕
create trigger t
Ïà¹ØÎĵµ£º
Êý¾Ý×Öµädict×ÜÊÇÊôÓÚOracleÓû§sysµÄ¡£
¡¡¡¡1¡¢Óû§£º
¡¡¡¡¡¡select username from dba_users;
¡¡¡¡¸Ä¿ÚÁî
¡¡¡¡¡¡alter user spgroup identified by spgtest;
¡¡¡¡2¡¢±í¿Õ¼ä£º
¡¡¡¡¡¡select * from dba_data_files;
¡¡¡¡¡¡select * from dba_tablespaces;//±í¿Õ¼ä
¡¡¡¡¡¡select tablespace_name,sum(bytes), sum(b ......
¶ÔÓÚWebÓ¦ÓÃÀ´Ëµ£¬×¢Éäʽ¹¥»÷ÓÉÀ´ÒѾ㬹¥»÷·½Ê½Ò²Î廨°ËÃÅ£¬³£¼ûµÄ¹¥»÷·½Ê½ÓÐSQL×¢Éä¡¢ÃüÁî×¢ÉäÒÔ¼°Ð½ü²Å³öÏÖµÄXPath×¢ÉäµÈµÈ¡£±¾ÎĽ«ÒÔSQL×¢ÉäΪÀý£¬ÔÚÔ´Â뼶¶ÔÆä¹¥»÷ÔÀí½øÐÐÉîÈëµÄ½²½â¡£
Ò»¡¢×¢Éäʽ¹¥»÷µÄÔÀí
×¢Éäʽ¹¥»÷µÄ¸ùÔ´ÔÚÓÚ£¬³ÌÐòÃüÁîºÍÓû§Êý¾Ý£¨¼´Óû§ÊäÈ룩֮¼äûÓÐ×öµ½ãþμ·ÖÃ÷¡£ÕâʹµÃ¹¥»÷ÕßÓлú»á½« ......
ÔÚÍøÉÏÕÒµÄÒ»¸ö·½·¨£¬¾ÍÒòΪһ¸öhostNameûÅäÖöԣ¬º¦µÃÎÒ»¨ÁË3¸öСʱ²Å¸ã¶¨
²âÊÔ»·¾³:
oracle·þÎñÆ÷: windowsXPϵͳ£¬ oracle9.2.0.7£¬Ö÷»úÃû£ºoracleHost
sqlserver·þÎñÆ÷:windows2003 r2ϵͳ£¬sqlserver 2000,Ö÷»úÃû£ºsqlHost
Ä¿µÄ£ºÔÚOracleÊý¾ÝÖзÃÎÊsqlserverÖеÄNorthwindÊý¾Ý¿â
1¡¢ÔÚ°²×°ORACLE9iʱ, Ò ......
´ÓÍøÂçÉÏÊÕ¹ÎÁËһЩ£¬ÒÔ±¸ºóÓÃ
create function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000)
as
begin
declare @word nchar(1),@PY nvarchar(4000)
set @PY=''
while len(@str)>0
begin
set @word=left(@str,1)
--Èç¹û·Çºº×Ö×Ö·û£¬·µ»ØÔ×Ö·û
set @PY=@PY+(case when unicode(@word) b ......
ʹÓô¥·¢Æ÷À´ÊµÏÖ
create table test(
id varchar(20),
sname varchar(20)
)
create TRIGGER [test_insert] ON [dbo].[test]
INSTEAD OF INSERT
AS
declare @str varchar(20)
declare @i integer
set @str = 'BV'+left(convert(char,getdate(),112),6)
select @i=isnull(max(cast(right(rtrim(id),len(id)-8 ......