Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script For Dropping All Empty Tables

Status
Not open for further replies.

19771947

Technical User
May 11, 2006
6
US
Hello All,

I have SQLServer 7. I want to prepare/generate the script so that I can drop all the user's table with 0 record count.

Please share if you have any such script.

Thnaks,

R
 
not sure if this will work as i dont have access to sql 7, but you can tweak it easy enough.

Code:
SELECT 'DROP TABLE ' + o.name, i.rowcnt 
FROM sysindexes i join sysobjects o on i.id = o.id
WHERE indid < 2 and (OBJECTPROPERTY(object_id(o.name), N'IsTable')) = 1 
and o.name <> 'sysdiagrams'
and i.rowcnt = 0
order by 2 desc
 
Jamfool,

Thanks a lot..It worked fine.

Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top