.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> Others >> Post New Question Subscribe to Interview Questions

Can Where clause be used with Truncate?

Posted By :shankey     Posted Date :July 31, 2011    Points :40   Category :Others 
No, Where clause cannot be used with truncate command.

You can also find related Interview Question to Can Where clause be used with Truncate?  below: 

Difference Between Delete and Truncate

  
.Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

. Truncate table also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.

. Truncate table is functionally identical to delete statement with no "where clause" both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.

. Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is.

. In truncate table the counter used by an identity column for new rows is reset to the seed for the column.

. If you want to retain the identity counter, use delete statement instead.

. If you want to remove table definition and its data, use the drop table statement.

. You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause. Because truncate table is not logged, it cannot activate a trigger.

. Truncate table may not be used on tables participating in an indexed view. (More...)

Truncate Prerequisites

  
To truncate a table or cluster, the table or cluster must be in your schema or you must have DROP ANY TABLE system privilege (More...)

What is the difference between TRUNCATE and DELETE commands?

  
TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back. WHERE clause can be used with DELETE and not with TRUNCATE. (More...)

Difference between Delete and Truncate?

  
Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

Truncate table also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.

Truncate table is functionally identical to delete statement with no where clause both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.

Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc. remains as it is.

In truncate table the counter used by an identity column for new rows is reset to the seed for the column.

If you want to retain the identity counter, use delete statement instead.

If you want to remove table definition and its data, use the drop table statement.

You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause. Because truncate table is not logged, it cannot activate a trigger.

Shashi Ray (More...)

Can we use Truncate command on a table which is referenced by FOREIGN KEY?

  
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity (More...)

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?

  
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query (More...)

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE ?

  
Both Clause are used to check the Condition at the time of Retrival of records in Database.
WHERE Clause is applied to each row before they are part of the GROUP BY function in a query.
Having Clause is basically used only with the GROUP BY function in a query. (More...)

Difference between DELETE and TRUNCATE commands ?

  
TRUNCATE TABLE is faster that DELETE TABLE and uses fewer system and transaction log resources.
Truncate will actually remove all the rows from a table and there will be no data in the table after we run the truncate command.
Delete command removes the rows from a table based on the condition that we provide with a WHERE clause. (More...)

Can we use Truncate command on a table which is referenced by FOREIGN KEY?

  
No. We cannot use Truncate command on a table with Foreign Key because of referential integrity (More...)

What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?

  
Having Clause is basically used only with the GROUP BY function in a query. WHERE Clause is applied to each row before they are part of the GROUP BY function in a query (More...)

What is the difference between TRUNCATE and DELETE commands?

  
1.TRUNCATE is a DDL command whereas DELETE is a DML command.
2.DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back.
3.WHERE can be used with DELETE and not with TRUNCATE. (More...)

Can we use Truncate command on a table which is referenced by FOREIGN KEY

  
No. We cannot use Truncate against of referential integrity. (More...)

difference between having and group by clause ?

  
Having is basically used for the any condition in Group by Clause

like if you are finding sum,max,min etc of any field you are using group by clause and sum is required with some condition then you use having clause for that condition

like select sum(Amount) as Amount from AD_tblAmount having (Sum(Amount)>0) (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend