Generic SQL query for an empty database

I am looking for a generic SQL query that replaces the following procedures:

-- -------------------------------------------------- -- Dropping existing FOREIGN KEY constraints -- -------------------------------------------------- -- -------------------------------------------------- -- Dropping existing tables -- -------------------------------------------------- 

Example:

The following query resets foreign keys for a specific table. Can it be converted to a common one? (Please do not offer to abandon the entire database, as I do not have permissions.)

 SELECT 'ALTER TABLE ' + OBJECT_NAME(parent_object_id) + ' DROP CONSTRAINT ' + name FROM sys.foreign_keys WHERE referenced_object_id = object_id('Student') 

Question :

How can I clear a database without dropping it?


Edit : Wait Wait, this is not a duplication issue! Another issue was releasing rows (or just data) that preserve relationships and tables. I am trying to delete all data, tables and relationships without dropping the database!

+4
source share
1 answer

Check this answer. How to remove all foreign key constraints in all tables?

This will remove foreign keys from all tables, you can add a drag and drop table to the loop or create a new loop after that to delete the tables

+1
source

All Articles