如果创建日期小于当前日期,则删除表

时间:2018-07-30 18:59:28

标签: sql sql-server database sql-server-2008

我试图学习如何根据创建日期删除表。如果该表的创建日期是今天,则保留该表,否则将其删除并重新创建。

如果存在的话,我可以删除该表,但是我只想删除该表是从比今天更早的日期创建的。

IF EXISTS (SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME 
= 'Search') DROP TABLE dbo.Search

(SELECT IssueID,IssueDate,D.Name As SectionName,C.Name As CategoryName,(B.FirstName + ' ' + B.LastName) As AssignedTo,Subject,Body,
Convert(date, getdate()) TableDate

INTO Search

FROM hdIssues A, hdUsers B, hdCategories C, hdSections D WHERE 
(A.AssignedToUserID = B.UserID AND A.CategoryID = C.CategoryID AND 
C.SectionID = D.SectionID))

0 个答案:

没有答案