Thursday, August 13, 2009

SQL Server -Msg 544, Level 16, State 1, Line 1 Cannot insert explicit value for identity column in table ' Table' when IDENTITY_INSERT is set to OFF.


Error Message:
Msg 544, Level 16, State 1, Line 1
Cannot insert explicit value for identity column in table  ' Table' when IDENTITY_INSERT is set to OFF.

    This error occurs when you are trying to insert value into a column which has IDENTITY property.To fix the error by setting IDENTITY_INSERT to ON.

Fix:
SET IDENTITY_INSERT [database_name].[schema_name].[tablename]  ON

INSERT INTO [database_name].[schema_name].[tablename] (ID,Name)   VALUES (11,'Viji')

SET IDENTITY_INSERT  
[database_name].[schema_name].[tablename] OFF

Friday, August 7, 2009

SQL Server - Transaction Logs Full

The transaction log is the part of the database to which the SQL Server writes all transactions before writing them to the database.
To verify the percentage of SQL transaction log space being used, run the following command
DBCC SQLPERF(LOGSPACE)
In case Transaction Log becomes full, when use one of  the following commands
BACKUP LOG DatabaseName WITH TRUNCATE_ONLY
For Example BACKUP LOG test WITH TRUNCATE_ONLY

DBCC SHRINKFILE(TransactionLogName, 1)
For Example DBCC SHRINKFILE(test_Log, 1)

For more details about log full

Thursday, July 30, 2009

Dropping a Table Constraint

Synatx:
ALTER TABLE Table_name
DROP CONSTRAINT Constraint_name
Example
ALTER TABLE employee
DROP CONSTRAINT FK_DEDUCTION_ID

Here simply drop a foregin key Constraint between two relational tables (ie., employee and Deduction)