Lesson 3: Delete database objects

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![yes](media/yes.png)Azure SQL Database ![yes](media/yes.png)Azure SQL Data Warehouse ![yes](media/yes.png)Parallel Data Warehouse This short lesson removes the objects that you created in Lesson 1 and Lesson 2, and then drops the database.

Before you delete objects, make sure you are in the correct database:

USE TestData;  
GO  

Revoke stored procedure permissions

Use the REVOKE statement to remove execute permission for Mary on the stored procedure:

REVOKE EXECUTE ON pr_Names FROM Mary;  
GO  

Drop permissions

  1. Use the DROP statement to remove permission for Mary to access the TestData database:
DROP USER Mary;  
GO  
  1. Use the DROP statement to remove permission for Mary to access this instance of [!INCLUDEssVersion2005]:
  DROP LOGIN [<computer_name>\Mary];  
  GO   
  1. Use the DROP statement to remove the store procedure pr_Names:
```sql  
DROP PROC pr_Names;  
GO  
```  
  1. Use the DROP statement to remove the view vw_Names:

Delete table

  1. Use the DELETE statement to remove all rows from the Products table:

  2. Use the DROP statement to remove the Products table:

Remove database

You cannot remove the TestData database while you are in the database; therefore, first switch context to another database, and then use the DROP statement to remove the TestData database:

USE MASTER;  
GO  
DROP DATABASE TestData;  
GO   

This concludes the Writing Transact\-SQL Statements tutorial. Remember, this tutorial is a brief overview and it does not describe all the options to the statements that are used. Designing and creating an efficient database structure and configuring secure access to the data requires a more complex database than that shown in this tutorial.