emi_sastra
asked on
DROP TABLE IF EMPTY DATA
Hi All,
I want to drop table if there is no data inside the table.
Usually I use : DROP TABLE TableName
How could I do it ?
Thank you.
I want to drop table if there is no data inside the table.
Usually I use : DROP TABLE TableName
How could I do it ?
Thank you.
Or you could do it simpler:
IF (SELECT 1 FROM <tableName>) IS NULL
BEGIN
DROP TABLE <tableName>
END
----------------
You can find me on: http://extremedev.blogspot.com/
IF (SELECT 1 FROM <tableName>) IS NULL
BEGIN
DROP TABLE <tableName>
END
----------------
You can find me on: http://extremedev.blogspot.com/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
oopps, yes - forgot to add TOP 1
----------------
You can find me on: http://extremedev.blogspot.com/
----------------
You can find me on: http://extremedev.blogspot.com/
ASKER
Hi All,
Thank you very much for your solution.
I think EvilPostIt code is the simplest.
Thank you.
Thank you very much for your solution.
I think EvilPostIt code is the simplest.
Thank you.
You calling me simple ;)
SELECT @count = Count(1) from <tablename>
IF @count = 0
BEGIN
DROP TABLE <tablename>
END