一些SQL代碼

2012022814:48
<!-- 關閉計數器,新增一筆資料,取得新增資料的識別碼 start-->
set nocount on;insert into PointLog(Account,PointRuleID,Points,FromWeb) values('bbb',9,0,'c');select @@identity as id;
<!-- 關閉計數器,新增一筆資料,取得新增資料的識別碼 end-->


刪除資料庫中超過一個月的信件
DELETE FROM Serv_MailBox WHERE (CreateTime < CONVERT(DATETIME, getdate()-30, 102))


清除資料庫 LOG 檔
backup log uc91 with NO_LOG


// UPDATE 使用 IN + 子查詢
UPDATE Msn_Modify SET Modify_Type = 'Mod' 
WHERE INFO_PK 
IN (
SELECT          Msn_Modify.INFO_PK
FROM            Msn_Modify INNER JOIN
Msn_Ticket ON Msn_Modify.INFO_PK = Msn_Ticket.INFO_PK AND 
Msn_Modify.Modify_Date <> Msn_Ticket.Modify_Date
)


// INSERT 使用 IN + 子查詢
INSERT INTO Msn_Modify
                          (INFO_PK, ROUTE, Modify_Type, Modify_Date)
SELECT         Msn_Ticket.INFO_PK, Msn_Ticket.ROUTE, 'Ins', Msn_Ticket.Modify_Date
FROM             Msn_Ticket LEFT OUTER JOIN
                          Msn_Modify Msn_Modify_1 ON 
                          Msn_Ticket.INFO_PK = Msn_Modify_1.INFO_PK
WHERE         (Msn_Modify_1.INFO_PK IS NULL)