https://github.com/emergentsoftware/sql-server-database-delete-data-or-drop-objects
This script allows the deletion of SQL Server table data without worrying about constraints by deleting in a specific table order. The script also allows you to delete any or all the SQL Server objects like tables, views, stored procedures, functions, user data types, sequences, and synonyms.
https://github.com/emergentsoftware/sql-server-database-delete-data-or-drop-objects
Last synced: 3 months ago
JSON representation
This script allows the deletion of SQL Server table data without worrying about constraints by deleting in a specific table order. The script also allows you to delete any or all the SQL Server objects like tables, views, stored procedures, functions, user data types, sequences, and synonyms.
- Host: GitHub
- URL: https://github.com/emergentsoftware/sql-server-database-delete-data-or-drop-objects
- Owner: EmergentSoftware
- License: mit
- Created: 2021-12-22T15:12:28.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-24T16:27:49.000Z (about 3 years ago)
- Last Synced: 2025-06-22T14:10:44.474Z (about 1 year ago)
- Language: TSQL
- Size: 11.7 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SQL-Server-Database-Delete-Data-or-Drop-Objects
## Description
This script allows the deletion of SQL Server table data without worrying about constraints by deleting in a specific table order. The script also allows you to delete any or all the SQL Server objects like tables, views, stored procedures, functions, user data types, sequences, and synonyms.
## Usage:
Use the changeable variables to either delete table data or drop database objects.
### Deleting Table Data
To delete all the rows in all the database tables set the variable `@DeleteData = 1`.
If you also want to reset all the identity columns so the next inserted row is 1, set the variable `@ReseedTableIdentity = 1`.
### Dropping/Deleting Database Objects
Each database object you might want to drop has its own variable. These variables names start with "@Drop" like `@DropTables`. So if you want to drop all the database tables you would set the variable `@DropTables = 1`.
## Notes:
There is no need to set `@DeleteData = 1` if you are also setting @DropTables = 1. It will be extra unneeded work.