Thursday, June 25, 2020

Delete Tables By Selecting Name

Delete By Selecting table name::

DECLARE @cmd varchar(4000)
DECLARE cmds CURSOR FOR
SELECT 'drop table [' + Table_Name + ']'
FROM INFORMATION_SCHEMA.TABLES
WHERE Table_Name LIKE 'NXTRPTEmployeeProfile_%'

OPEN cmds
WHILE 1 = 1
BEGIN
    FETCH cmds INTO @cmd
    IF @@fetch_status != 0 BREAK
    EXEC(@cmd)
END
CLOSE cmds;
DEALLOCATE cmds

No comments:

Post a Comment

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.