I used to receive frequent requests to clear data from my database, so I deleted all records from tables using multiple approaches. I will walk you through all the approaches to do this.
Note: Before deleting the record from the table, properly back up it for the safer side.
Approach-1: Using the DELETE Statement
Check out: How To Drop All Constraints On A Table In SQL Server
One primary method is the DELETE Statement, which deletes all the records from a table in the SQL server.
Syntax
DELETE FROM TableName;
Example
Let us delete all the records from the Order table. Before that, let us see the records in the Order table using the select query below.
Select * from [Order]
After executing the above query, we got the lists of records available in the Order table.
Now, we will execute the below query to delete all the records.
DELETE FROM [Order];
After executing the above query, the query was executed successfully, as shown in the screenshot below.
Now, to cross-check, let us verify using the select query below.
Select * from [Order]
Now, you can see the data got deleted successfully, and there is no data available in this table, as shown in the screenshot below.
Approach-2: Using the TRUNCATE TABLE statement
You can check out how to truncate a table in SQL server for the complete steps.
Conclusion
You can use the Delete table/Truncate table statement to delete the records from a table in the SQL server. For faster operation, you can use the Truncate table statement. Refer to the above information for the complete steps.
You may also like following the articles below.
- How To Find A Table In SQL Server
- How To Duplicate A Table In SQL Server
- How To Check User Permissions On Table In SQL Server
- How To Check Table Description In SQL Server
Grey is a highly experienced and certified database expert with over 15 years of hands-on experience in designing, implementing, and managing complex database systems. Currently employed at WEX, USA, Grey has established a reputation as a go-to resource for all things related to database management, particularly in Microsoft SQL Server and Oracle environments. He is a Certified Microsoft SQL Server Professional (MCSE: Data Management and Analytics) and Oracle Certified Professional (OCP), with Extensive database performance tuning and optimization knowledge and a proven track record in designing and implementing high-availability database solutions.