| title | T-SQL Tutorial: Delete database objects | |
|---|---|---|
| description | This short lesson removes the objects that you created in Lesson 1 and Lesson 2, and then drops the database. | |
| author | MikeRayMSFT | |
| ms.author | mikeray | |
| ms.reviewer | randolphwest | |
| ms.date | 04/19/2023 | |
| ms.service | sql | |
| ms.subservice | t-sql | |
| ms.topic | reference | |
| ms.custom |
|
|
| helpviewer_keywords |
|
|
| monikerRange | >=aps-pdw-2016 || =azuresqldb-current || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current || =fabric-sqldb |
[!INCLUDEsql-asdb-asdbmi-pdw-fabricsqldb]
Note
The Get Started Querying with Transact-SQL learning path provides more in-depth content, along with practical examples.
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;
GOUse the REVOKE statement to remove execute permission for Mary on the stored procedure:
REVOKE EXECUTE ON pr_Names FROM Mary;
GO-
Use the
DROPstatement to remove permission forMaryto access theTestDatadatabase:DROP USER Mary; GO
-
Use the
DROPstatement to remove permission forMaryto access this instance of [!INCLUDEssVersion2005]:DROP LOGIN [<computer_name>\Mary]; GO
-
Use the
DROPstatement to remove the store procedurepr_Names:DROP PROC pr_Names; GO
-
Use the
DROPstatement to remove the viewvw_Names:DROP VIEW vw_Names; GO
-
Use the
DELETEstatement to remove all rows from theProductstable:DELETE FROM Products; GO
-
Use the
DROPstatement to remove theProductstable:DROP TABLE Products; GO
You can't 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;
GOThis concludes the Writing [!INCLUDEtsql] Statements tutorial. Remember, this tutorial is a brief overview and it doesn't 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.