[SQL]´¥·¢Æ÷µÄʹÓÃ
1. ´´½¨´¥·¢Æ÷, ÔÚmssqlϵĴ¥·¢Æ÷µÄʹÓÃ:Db->±í->Ñ¡Ôñ±íÃû->ËùÓÐÈÎÎñ(ÓÒ¼ü)->¹ÜÀí´¥·¢Æ÷
2. µ±±í±»¸üÐÂ\²åÈë\ɾ³ýºó,¶¼¿ÉÒÔͨ¹ý¶¨Òå´¥·¢Æ÷À´ÏìÓ¦¸Ãʼþ,´Ó¶ø½øÐÐÏàÓ¦µÄ´¦Àí! ÈçÒ»¸öѧÉúתϵÁË,ÆäѧºÅ±»¸ü»»ÁË,ËûËù½èµÄͼÊé¶ÔÓ¦µÄѧºÅÒ²ÏàÓ¦ÐèÒª¸Ä¶¯,Õâ¸öÎÒÃÇ¿ÉÒÔֻͨ¹ýupdateÆäѧºÅ,ºÍѧºÅÏà¹ØÁªµÄ±íÓÉ´¥·¢Æ÷À´¸üÐÂ!
3. example:
CREATE TRIGGER [user_update] ON [dbo].[Users]
FOR INSERT
AS
BEGIN
DECLARE curUserid CURSOR FOR SELECT [USERID] from [INSERTED]
OPEN curUserid
DECLARE @insertid integer
FETCH NEXT from curUserid INTO @insertid
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE Users SET UserName="ycli_in" where UserID = @insertid
FETCH NEXT from curUserid INTO @insertid
END
CLOSE curUserid
DEALLOCATE curUserid
END
×¢Ò⽫ $$ -> \\
Ïà¹ØÎĵµ£º
ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLE µÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦À ......
»úÆ÷Çé¿ö
p4: 2.4
ÄÚ´æ: 1 G
os: windows 2003
Êý¾Ý¿â: ms sql server 2000
Ä¿µÄ: ²éѯÐÔÄܲâÊÔ,±È½ÏÁ½ÖÖ²éѯµÄÐÔÄÜ
SQL²éѯЧÂÊ step by step
-- setp 1.
-- ½¨±í
create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick varchar(50) not null default '',
classid int not nul ......
²é¿´»ØÊÕÕ¾Öбí
select object_name,original_name,partition_name,type,ts_name,createtime,droptime from recyclebin;
»Ö¸´±í
SQL
>flashback table test_drop to before drop;»ò
SQL
>flashback table "BIN$b+XkkO1RS5K10uKo9BfmuA==$0" to befor ......
¹¤×÷ÖÐÅöµ½µÄС¼¼ÇÉ£¬±ÈÈç˵ҪÓÃÊý¾Ý±íÀïÈ¡³ö×¢²áÓû§µÄ×ÊÁÏ£¬ÐÔ±ðΪ1ÔòÏÔʾΪÄÐÉú£»ÐÔ±ðΪ2ÔòÏÔʾΪŮÉú£»ÒÔÇ°¶¼ÊÇ´Ó±íÀïÈ¡³öÊý¾Ý£¬È»ºóÔÙÓôúÂë½øÐÐÅжϣ¬Îª1ÔòÏÔʾΪÄÐÉú£»Îª2ÔòÏÔʾΪŮÉú£»Æäʵµ¥ÓÃSQLÓï¾ä¾Í¿ÉÒÔ×öµ½£¬ÈçÏ£º
Ö±½ÓʹÓÃcase when else Óï¾ä
Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseË ......
SELECT DISTINCT '['+user_name(b.uid)+'].['+b.name+']' AS ¶ÔÏóÃû,b.type AS ÀàÐÍ
from sysdepends a,sysobjects b
WHERE b.id=a.depid
AND a.id=OBJECT_ID('¹ý³ÌÃû');
EXEC SP_DEPENDS '¹ý³ÌÃû'; ......