IT tutorials
 
Technology
 

SQL Server 2012 : Dropping Tables

12/27/2013 8:13:33 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

When you drop a table, you are deleting it from the database. When you perform this action, you are also deleting the table data, indexes, triggers, constraints, and permissions that were defined on the table. In certain circumstances, you are not allowed to drop a table. For example, if your table is referenced by another table via a foreign key constraint, the foreign key constraint must be removed from the referring table first before the table in question can be deleted. Also, any stored procedures or views that reference the table will need to be dropped or changed before the table in question can be dropped.

To help illustrate deleting a table, let’s create two tables: Customers and Accounts. The Accounts table will contain a column customer_id that references the customer_id column in the Customers table. The script to create these tables is as follows:

CREATE TABLE Customers
(customer_id INT PRIMARY KEY,
customer_name NVARCHAR(50) NOT NULL)
GO

CREATE TABLE Accounts
(customer_id INT REFERENCES Customers(customer_id),
account_balance MONEY)
GO

To drop the Customers table using SSMS, simply right-click Customers in Object Explorer and select Delete. This will launch the Delete Object dialog box shown in Figure 1.

images

Figure 1. Delete Object dialog box

If you click OK to delete, you will get an error stating “Drop failed for Table ‘dbo.Customers’. (Microsoft.SqlServer.Smo).” If you click the error link, you will find more details, including the following text: “Could not drop object ‘dbo.Customers’ because it is referenced by a FOREIGN KEY constraint. (Microsoft SQL Server, Error: 3726).” Since the Customers table is referenced by the Accounts table, you can’t drop it until you address the foreign key reference. To determine these issues before you actually issue the drop command, you can click the Show Dependencies button. This will launch the Customers Dependencies dialog box shown in Figure 2.

images

Figure 2. Customers Dependencies dialog box

Figure 2 clearly shows that the Accounts table references the Customers table.

The DDL statement for dropping a table is the DROP TABLE statement. To drop both tables, use the following script:

DROP TABLE Accounts
GO
DROP TABLE Customers
GO
 
Others
 
- SQL Server 2012 : Altering Tables, Adding Constraints
- Sharepoint 2010 : Planning Your Search Deployment - Performance (part 3) - Limitations and Hard-Coded Boundaries
- Sharepoint 2010 : Planning Your Search Deployment - Performance (part 2) - Scaling, Availability
- Sharepoint 2010 : Planning Your Search Deployment - Performance (part 1) - Performance Reports
- Windows Server 2008 : Starting and Using PowerShell - Using Comparison Operators, Understanding Pipelining
- Windows Server 2008 : Starting and Using PowerShell - Understanding PowerShell Variables
- Windows Server 2008 : Starting and Using PowerShell - Redirecting Output with Windows PowerShell, Understanding PowerShell Errors
- Windows Server 2008 : Starting and Using PowerShell - Exploring get-member
- Windows Server 2008 : Starting and Using PowerShell - Creating Aliases, Discovering Windows PowerShell Commands
- Exchange Server 2010 : Managing Mailbox Databases (part 2) - Properties of a Mailbox Database
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us