Posts

Showing posts with the label Sql Server
SQL Error : String or binary data would be truncated While working on an application I found an error 'String or binary data would be truncated.After finding the solution I thought to publish it. Whenever you see the message :   string or binary data would be truncated That means the field is NOT big enough to hold my data. Check the table structure you will find that the length of one or more fields is not big enough to hold the data you trying to insert. For example : As the column ' FIRSTNAME VARCHAR(5)' is able to hold 5 characters and you are trying to put characters greater than  5 in it then you will get this error.Increase the size of the field or decrease the value while inserting.

When to use Truncate and Delete Command in SQL

INTRODUCTION Truncate and Delete in SQL are two commands which is used to remove or delete data from table. Though quite basic in nature both Sql commands can create lot of trouble until you are familiar with details before using it. An Incorrect choice of command can result is either very slow process or can even blew up log segment, if too much data needs to be removed and log segment is not enough. That's why it's critical to know when to use truncate and delete command in SQL but before using these you should be aware of the Differences between Truncate and Delete , and based upon them, we should be able to find out when DELETE is better option for removing data or TRUNCATE should be used to purge tables. I have still seen people firing delete command just to empty a table with millions of records which eventually lock the whole table for doing anything and take ages to complete or Simply blew log segment or hang the machine. Truncate Use truncate table if you need ...

Difference Between Delete & Truncate in Sql Server

INTRODUCTION While working on database, we are using Delete and Truncate without knowing the differences between them and when to use them . In this article we will discuss the difference between Delete and Truncate in Sql. Delete Delete is a DML command. Delete statement is executed using a row lock,each row in the table is locked for deletion. We can specify filters in where clause. It deletes specified data if where condition exists. Delete activities a trigger because the operation are logged individually. Slower than Truncate because it Keeps logs Truncate Truncate is a DDL command. Truncate table always lock the table and page but not each row.As it removes all the data. Cannot use Where condition.  It Removes all the data. Truncate table cannot activate a trigger because the operation does not log individual row deletions. Faster in performance wise, because it doesn't keep any logs. Note Delete and Truncate both can be rolled back when used with Tr...

Rollback Table after Truncate Command in Sql Server

Image
It is misconception among people that Truncate cannot be rolled back. But in reality Truncate operation can be Rolled Backed before Commit.Here is the Sql query -- Create table  CREATE TABLE Employee                   ( EmpID INT PRIMARY KEY ,                     EmpSalary INT                   ) -- Check data before Truncate SELECT * FROM Employee --Begin  Transaction BEGIN TRAN --Truncate Table TRUNCATE TABLE Employee GO --Check data after Truncate SELECT * FROM Employee GO --Rollback Transaction ROLLBACK TRAN GO --Check the data after Rollback SELECT * FROM Employee GO Note:- If Transaction is done, mean Committed...