Drop table in sql.
SQL DROP TABLE Statement.
DROP TABLE Statement is used to
delete the table in SQL Server. Sometimes user need to delete the existing
table. User has to use DROP TABLE statement to delete the unwanted table. After
executing DROP TABLE statement the table removes from the SQL server.
The DROP TABLE statement removes the data and SQL server table structure.
To delete record(s) from table, user can use TRUNCATE or DELETE Statement in SQL Server.
To delete a table from SQL Server database. Disable or remove the FOREIGN KEY CONSTRAINT. Without disabling or removing FOREIGN KEY CONSTRAINT the table can not drop.
To delete record(s) from table, user can use TRUNCATE or DELETE Statement in SQL Server.
To delete a table from SQL Server database. Disable or remove the FOREIGN KEY CONSTRAINT. Without disabling or removing FOREIGN KEY CONSTRAINT the table can not drop.
DROP TABLE Statement's syntax:
DROP TABLE table_name
[Note: Be careful while deleting
table. After deleting table the information loss completely.]
DROP TABLE Example:
Now, Create a new table and DROP this table.
We are going to create a new table named CustomerDetails that store the customer details.
Create Table CustomerDetails ( CustomerId int NOT NULL constraint pkPrimary primary key, Name varchar(30)NOT NULL, Address Varchar(30)NOT NULL, City Varchar(20)NOT NULL, ZipCode Varchar(20)NOT NULL, Phone Varchar(30)NULL, Description Varchar(200)NULL ) Insert into CustomerDetails Values('1','SMITH','NY','NY','1001',NULL,NULL) Insert into CustomerDetails Values('2','ANU','NY','NY','1001',NULL,NULL) Insert into CustomerDetails Values('3','DEU','NY','NY','1001',NULL,NULL) Insert into CustomerDetails Values('4','LILI','NY','NY','1001',NULL,NULL) Insert into CustomerDetails Values('5','ZOZI','NY','NY','1001',NULL,NULL)
We have created CustomerDetails table and inserted some values into the table.
Now display the records from table.
Select * From CustomerDetails
Now, the following sql statement drop the CustomerDetails table.
DROP TABLE CustomerDetails
Now, If user execute the following statement. SQL Server will throw the error
Select * from CustomerDetails.
DROP TABLE example in video:
DROP TABLE example in Image
No comments:
Post a Comment