Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
if there any possible to delete single entity using TRUNCATE in sql
_Asif_ 29-May-15 7:04am    
What do you mean by single entity? and why TRUNCATE? why not DELETE?
V Senthil Kumar 29-May-15 8:12am    
if you used id in primary key .after you delete means you got the id values is not in order so i need single entity to delete using truncatee

If by "single entity" you mean a single row then the answer is "No" - you cannot use Truncate in sql to do that - see the Documentation[^] for Truncate
Removes all rows from a table without logging the individual row deletions. TRUNCATE TABLE is similar to the DELETE statement with no WHERE clause; however, TRUNCATE TABLE is faster and uses fewer system and transaction log resources.

If you have the means of identifying which row you want to remove then include those details in a WHERE clause e.g.
DELETE FROM tablename where column1 = 'A' and column2 = '2'
or however you know which row to delete.

If by "single entity" you mean a table then the answer is still "No" - the table will still exist but will be empty (refer to documentation link above).
In that instance you will need to use DROP TABLE[^]. E.g.
IF OBJECT_ID(N'dbo.tablename', N'U') IS NOT NULL
    DROP TABLE dbo.tablename;
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tablename]') AND TYPE IN (N'U'))
DROP TABLE [dbo].[tablename]
Share this answer
Sascha Lefèvre 29-May-15 9:50am    
thank you. ................
Share this answer
Sascha Lefèvre 29-May-15 9:49am    
You posted this as a solution. Please delete it and use the button "Have a Question or Comment?" below the answer to leave a comment instead :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900