Hi,
I have a database 'Database1'.
Inside that i have multi-company structure as Company1, Company2 & so on.
I want to delete all the tables within Comapany1 including system tables, data tables with their data at one instance. Currently, i have to go to each table and press delete manually.
Can anyone please help with SQL query to carry out this task.
eg: Each type has 3 kinds of tables created. I want to delete entire things of Company1
dbo.Company1.MySettings.data
dbo.Company1.MySettings.sidedata
dbo.Company1.MySettings.audit
dbo.Company1.MyContacts.data
dbo.Company1.MyContacts.sidedata
dbo.Company1.MyContacts.audit

sudipta sanyalPosted Apr 24, 2014, 2:37 AM
Naitik JaniPosted Apr 23, 2014, 7:25 AM
Yes..you are right..
But that needs to be taken care by us which tables are referenced tables and which are primary tables but still will check if i can find another way that this list comes in way reference table first and last primary table.
Jasmine NagrechaPosted Apr 21, 2014, 7:24 AM
Firstly thank you so much for your prompt reply.
The drop query works well with most tables. However, for few types it throws error of foreign key constraint and for few permission not available errors.
But when i delete the base type, i can than delete the reference data.
Overall much eased task now. Thanks once again.
regards,
Jasmine N
Naitik JaniPosted Apr 21, 2014, 4:48 AM
You can try this commands
SELECT 'DROP TABLE "' + TABLE_NAME + '"'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME LIKE 'company1%'
So you will get list of Table names with queries and you can select result and paste it in Query window and after executing script all tables will be dropped.
You can create script for same.
Hope this helps !!
Thanks,
Naitik