問題描述
有沒有辦法在 Transact-SQL 中創建行 24 小時后自動刪除行?
Is there a way to automatically delete a row 24 hours after its creation in Transact-SQL?
我正在制作一個網站(學習體驗),用戶在注冊后需要單擊通過電子郵件發送的驗證鏈接.我希望用戶在 24 小時內驗證自己.
I'm making a site (learning experience) where the user needs to click a validation link sent by e-mail once they register. I want the users to validate themselves within 24 hours.
我想我需要的是觸發器,但我真的不確定語法,甚至不確定是否可能.
I suppose what I'd need is a trigger, but I'm really not sure on the syntax, nor if it is even possible.
推薦答案
我不確定您的架構,但我會采用不同的方式.我將針對與驗證鏈接相對應的數據庫記錄有一個日期/時間.當他們單擊該鏈接時,請驗證數據庫記錄的日期和時間是否在當前時間的 24 小時內.如果是,則允許,否則拒絕.
I'm not sure of your schema but I would do it a different way. I would have a date/time against the database record that corresponds to the validation link. When they click the link, verify that the date and time of the database record is within 24 hours of the current time. If so, allow it, otherwise reject it.
這篇關于插入后 24 小時刪除記錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!