Pages

Friday, August 9, 2013

How to Delete Tables and Truncate Tables

Microsoft SQL Server has a "truncate" statement that deletes all records in a database table. The "truncate" statement does not delete the table, but the "drop table" statement deletes the table structure and its data. The statement you use depends on if you want to completely remove the table from the database or only remove the data and leave the structure to store data in the future.

Instructions

    1

    Click the Windows "Start" button and select "All Programs." Click the "SQL Server" program group, then click "SQL Server Management Studio" shortcut to open the database software.

    2

    Click "New Query" in the Management Studio menu. A SQL query editor opens on the database server.

    3

    Type the following code to truncate and remove all data from the table but leave the table structure intact:

    truncate table table_name

    Replace "table_name" with the name of the table you want to edit. Press "F5" to execute your statement. There is no confirmation before you delete the data, so make sure you want to remove all data before running this statement.

    4

    Type the following code to delete the data and the table structure:

    drop table table_name

    Replace "table_name" with the name of your table. Like the truncate statement, there is no confirmation before running this statement, so make sure you want to remove the table before running a drop statement. Press "F5" to execute the statement.

0 comments:

Post a Comment