Violation of … constraint ‘…’. Cannot insert duplicate key in object ‘…’ (Msg 2627)

SQL Server’s error “Violation of … constraint ‘…’. Cannot insert duplicate key in object ‘…’” can appear when a user tries to insert a non-unique value into a table’s unique column such as the primary key. Look at the following syntax:

CREATE TABLE Table_1
(ID INT NOT NULL PRIMARY KEY, 
 NAME VARCHAR(10) NOT NULL, 
 AGE date);

Read More

CREATE DATABASE failed. Some file names listed could not be created (Msg 1802)

The error “CREATE DATABASE failed. Some file names listed could not be created. Check related errors.” can occur when the user tries to create a database with file names specified. To understand when this error can appear and how to avoid it, let’s consider the following syntax:

CREATE DATABASE Adventureworks 
ON PRIMARY
( NAME = Adventureworks_Data,
  FILENAME = 'Adventureworks_Data.mdf',
  SIZE = 0,
  MAXSIZE = 30,
  FILEGROWTH = 10% )
LOG ON
( NAME = Adventureworks_Log,
  FILENAME = 'Adventureworks_Log.ldf',
  SIZE = 3MB,
  MAXSIZE = 20MB,
  FILEGROWTH = 3MB );
GO

Read More

Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim (Msg 1205)

“Transaction was deadlocked” error occurs when two or more sessions are waiting to get a lock on a resource which has already locked by another session in the same blocking chain.  As a result, none of the sessions can be completed and SQL Server has to intervene to solve this problem. It gets rid of the deadlock by automatically choosing one of the sessions as a victim and kills it allowing the other session to continue. In such case, the client receives the following error message:

Transaction (Process ID) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

and the killed session is rolled back. As a rule, the victim is the session that requires the least amount of overhead to rollback. Read More

Database ‘Adventureworks’ cannot be opened. It is in the middle of a restore (Msg 927)

To understand how to avoid “Database ‘Adventureworks’ cannot be opened. It is in the middle of a restore” error let’s consider the following example:

Assume, in the database some crucial data were deleted, and the restore operation was started

RESTORE DATABASE Adventureworks FROM DISK = 'Adventureworks_full.bak' WITH NORECOVERY, REPLACE 

Read More

Unknown object type ‘…’ used in a CREATE, DROP, or ALTER statement (Msg 343)

Let’s consider the error “Unknown object type ‘…’ used in a CREATE, DROP, or ALTER statement” in the following example:

There is a need to add one more column “Column4” in the table “Table_1” which is located in the database “Adventureworks”. To execute this operation has been used the next syntax

ALTER Table_1 
ADD Column4 INT;

Read More

A transport-level error has occurred when sending the request to the server (Msg 233)

The error “A transport-level error has occurred when sending the request to the server”  can occur when the SQL Server client cannot connect to the server. The reason for the lack of connection can become a wrong-configured remote connection. In this case, SQL Server will send the following message:

Msg 233, Level 20, State 0, Line 0
A transport-level error has occurred when sending the request to the server. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.)

Read More

Incorrect syntax near the keyword ‘PRIMARY’ (Msg 156)

The error “Incorrect syntax near the keyword ‘PRIMARY’” can occur if the user tries to execute the command with a wrong syntax. Let’s consider the following example:

Assume there is a database “Adventureworks” in which new table “Table_2” was created. Two columns “Column1” and “Column2” were added to the “Table_2”, “Column1” was selected as Primary Key. Please pay attention to the following syntax:

CREATE TABLE Table_2
(Column1 INT NOT NULL,
Column2 VARCHAR(300)
CONSTRAINT Table_2_Coumnl1 PRIMARY KEY CLUSTERED (Column1))

Read More