Home

Table Maintenance

 

Introduction

Table maintenance consists of reviewing or changing its aspects. This includes reviewing the list of tables of a database, renaming a table, or deleting it.

Tables Review

To see the list of tables of a database in the Enterprise Manager, in the left frame, you can click the Tables:

To see the list of tables of a database using SQL, in a Query window of the SQL Query Analyzer, after specifying the database, execute sp_help (it is a stored procedure). Here is an example:

 
 

Renaming a Table

If you find out that the name of a table is not appropriate, you can change it.

To change the name of a table in the Enterprise Manager, in the right frame, right-click the table and click Rename. Type the desired name and press Enter.

To change the name of a table with code, execute sp_rename, followed by the current name of the table, a comma, and the new desired name of the table. Here is an example:

sp_rename 'StaffMembers', 'Employees'
GO

In this case, the interpreter would look for a table named StaffMembers in the current or selected database. If it find it, it would rename it Employees.

 

Deleting a Table

If you have an undesired table in a database, you can remove it. To delete a table in the Enterprise Manager, in the right frame, right-click it and click Delete. You will receive a warning give you a chance to confirm your intentions. If you still want to remove the table, select it in the list and click Drop All.

To delete a table using SQL code, use the following formula:

DROP TABLE TableName

The DROP TABLE expression is required and it is followed by the name of the undesired table. When you execute the statement, you will not receive a warning before the table is deleted.

 

Previous Copyright © 2004-2005 FunctionX, Inc. Next