Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 60

#1

Msg 8140, Level 16, State 0, Line 1 More than one key specified in column level
%ls constraint, table '%.*ls'.

SQL Server Error Message:

More than one key specified in column level %ls constraint, table '%.*ls'.

What and Why "this Error":

This error occurs when you try to create a column level constraint with a unequal
number of columns on both sides of the constraint. For example: the following
statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 INT
)
GO
CREATE TABLE TEST2
(
COL3 INT CONSTRAINT FRNKY FOREIGN KEY REFERENCES TEST(COL1,COL2)
)
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is you must specify the same number of columns on both
sides of the constraint. In the above example we try to create a FOREIGN KEY
constraint on the column COL3 of the table TEST2. This column references more
than one column in table TEST. This raises the error. By removing one extra column
from the reference statement, the above statement will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT PRIMARY KEY,
COL2 INT
)
GO
CREATE TABLE TEST2
(
COL3 INT CONSTRAINT FRNKY FOREIGN KEY REFERENCES TEST(COL1)
)
GO
DROP TABLE TEST2
GO
DROP TABLE TEST
GO

#2
Msg 8145, Level 16, State 1, Procedure sp_dboption, Line 0
%.*ls is not a parameter for procedure %.*ls.

SQL Server Error Message:

Procedure sp_dboption, Line 0 %.*ls is not a parameter for procedure %.*ls.

What and Why "this Error":

This error occurs when you try to use an invalid parameter for a system-supplied
stored procedure. For example: the following statement will raise the above error.

USE tempdb
CREATE DATABASE ABC
GO
USE ABC
EXEC sp_dboption N'ABC', @updateusage = 'TRUE'
GO
USE tempdb
DROP DATABASE ABC
GO

Action Required to resolve this Error:

The solution to this error is the SQL Server system-supplied stored procedures only
except their fixed set of mandatory and optional parameters. In the above example
we try to call the system procedure sp_dboption with the invalid parameter
@updateusage. This raises the error.

USE tempdb
CREATE DATABASE ABC
GO
USE ABC
EXEC sp_dboption N'ABC'
GO
USE tempdb
DROP DATABASE ABC
GO

#3
Msg 8146, Level 16, State 2, Procedure t, Line 0 Procedure %.*ls has no
parameters and arguments were supplied.

SQL Server Error Message:

Procedure %.*ls has no parameters and arguments were supplied.

What and Why "this Error":

This error occurs when you try to pass parameter values to a stored procedure that
are not expected by the procedure. For example: the following statement will raise
the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
INSERT INTO TEST SELECT 1
UNION ALL SELECT 10
UNION ALL SELECT 15
UNION ALL SELECT 18
UNION ALL SELECT 12
UNION ALL SELECT 120
GO
CREATE PROCEDURE TESTPROC
AS
BEGIN
SELECT * FROM TEST
END
GO
EXEC TESTPROC @VRBL=18
GO
DROP TABLE TEST
GO
DROP PROCEDURE TESTPROC
GO
Action Required to resolve this Error:

The solution to this error is you can only pass values for those parameters to a
stored procedure that are also expected by this procedure. In the above example
we try to pass values for the parameters @VRBL to the procedure TESTPROC.
Because procedure TESTPROC has no such parameters, the error is raised.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
INSERT INTO TEST SELECT 1
UNION ALL SELECT 10
UNION ALL SELECT 15
UNION ALL SELECT 18
UNION ALL SELECT 12
UNION ALL SELECT 120
GO
CREATE PROCEDURE TESTPROC
@VRBL INT
AS
BEGIN
SELECT * FROM TEST WHERE COL1 =@VRBL
END
GO
EXEC TESTPROC @VRBL=18
GO
DROP TABLE TEST
GO
DROP PROCEDURE TESTPROC
GO

#4
Msg 8147, Level 16, State 1, Line 1 Could not create IDENTITY attribute on nullable
column '%.*ls', table '%.*ls'.

SQL Server Error Message:

Could not create IDENTITY attribute on nullable column '%.*ls', table '%.*ls'.

What and Why "this Error":


This error occurs when you try to create the IDENTITY property on a numerical
column that allowd NULLs. For example: the following statement will raise the
above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NULL IDENTITY
)
GO

Action Required to resolve this Error:

The solution to this error is the IDENTITY property can only be created on NOT
NULL constrained numerical columns. In the above example we try to create the
IDENTITY property on the column COL1 of the table TEST. Because this columns
allows NULLs, the error is raised. By removing the NULL from the above statement,
it will execute.

USE tempdb
CREATE TABLE TEST
(
COL1 INT IDENTITY
)
GO
DROP TABLE TEST
GO

#5
Msg 8150, Level 16, State 0, Line 1 Multiple NULL constraints were specified for
column '%.*ls', table '%.*ls'.

SQL Server Error Message:

Multiple NULL constraints were specified for column '%.*ls', table '%.*ls'.

What and Why "this Error":

This error occurs when you try to create more than one NULL constraint for a
column. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NULL NULL
)
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is you can specify only one NULL constrain for a single
column. In the above example we try to specify multiple NULL constraints for the
column COL1 of the table TEST. This raises the error. By removing one NULL from
the above statement, it will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NULL
)
GO
DROP TABLE TEST
GO

#6
Msg 8151, Level 16, State 0, Line 1 Both a PRIMARY KEY and UNIQUE constraint
have been defined for column '%.*ls', table '%.*ls'. Only one is allowed

SQL Server Error Message:

Both a PRIMARY KEY and UNIQUE constraint have been defined for column '%.*ls',
table '%.*ls'. Only one is allowed

What and Why "this Error":

This error occurs when you try to create both a PRIMARY KEY and a UNIQUE
constraint on the same set of columns in a single statement. For example: the
following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT CONSTRAINT PRMRKY PRIMARY KEY
CONSTRAINT UNQ UNIQUE
)
GO
Action Required to resolve this Error:

The solution to this error is you cannot create both constraints in a single
statement, but rather need to split them in to two separated statements. In the
above example we try to create both a PRIMARY KEY and a UNIQUE constraint on
the column COL1 of the table TEST. This raises the error. You can execute the
above statement by spliting the constraint statement into two as shown in the
following statement.

USE tempdb
CREATE TABLE TEST
(
COL1 INT CONSTRAINT PRMRKY PRIMARY KEY
)
GO
ALTER TABLE TEST ADD CONSTRAINT UNQ UNIQUE(COL1)
DROP TABLE TEST
GO

#7
Msg 8152, Level 16, State 14, Line 5 String or binary data would be truncated.

SQL Server Error Message:

String or binary data would be truncated.

What and Why "this Error":

This error occurs when you try to insert a string with more characters than the
column can maximal accommodate. For example: the following statement will raise
the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 CHAR
)
GO
INSERT INTO TEST VALUES ('HECTOR')
DROP TABLE TEST
GO
Action Required to resolve this Error:

The solution to this error is you must either shorten the string to be isnerted to
widen the column. In the above example we try to insert a string 'HECTOR' with a
length of 6 into the column COL1 of the table TEST. Because COL1 is of the data
type CHAR(1), the error is raised. To execute the above statement you should
either pass CHAR(6) to insert ‘HECTOR’ or you should use VARCHAR.

USE tempdb
CREATE TABLE TEST
(
COL1 CHAR(10)
)
GO
INSERT INTO TEST VALUES ('HECTOR')
DROP TABLE TEST
GO

OR

USE tempdb
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
INSERT INTO TEST VALUES ('HECTOR')
DROP TABLE TEST
GO

#8
Msg 8155, Level 16, State 2, Line 2 No column was specified for column %d of
'%.*ls'.

SQL Server Error Message:

No column was specified for column %d of '%.*ls'.

What and Why "this Error":


This error occurs when a column of a derived table cannot be assigned a unique
column name. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) FROM TABLE1 GROUP BY STDNAME)ALIAS
GO
DROP TABLE TABLE1
GO

Action Required to resolve this Error:

The solution to this error is You must specify (either explicitly or implicitly) a
column name of each column of a derived table. In the above example we try to
derive a table. Because we use the MAX() aggregate function on the column STDID,
SQL Server cannot implicitly assign a name to that column. And because we haven't
explicitly specified a column alias name, the error is raised. I have specified the
column alias name & as result the above statement execute successfully.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) AS COLUMN_ALIAS_NAME FROM TABLE1 GROUP
BY STDNAME)ALIAS
GO
DROP TABLE TABLE1
GO

#9
Msg 8156, Level 16, State 1, Line 2 The column '%.*ls' was specified multiple times
for '%.*ls'.

SQL Server Error Message:

The column '%.*ls' was specified multiple times for '%.*ls'.

What and Why "this Error":

This error occurs when you assign the same alias to more than one column of a
derived table. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) AS ALIASNAME,ALIASNAME FROM TABLE1
GROUP BY STDNAME)ALIAS
GO
DROP TABLE TABLE1
GO

Action Required to resolve this Error:

The solution to this error is You must specify (either explicitly or implicitly) a
column name of each column of a derived table. In the above example we try to
derive a table in which we try to assign the alias ALIASNAME more than once. This
raises the error. By removing extra unneeded ALIASNAME from the above
statement, it will execute successfully.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) AS ALIASNAME FROM TABLE1 GROUP BY
STDNAME)ALIAS
GO
DROP TABLE TABLE1
GO
#10
Msg 8158, Level 16, State 1, Line 2 '%.*ls' has more columns than were specified
in the column list.

SQL Server Error Message:

'%.*ls' has more columns than were specified in the column list.

What and Why "this Error":

This error occurs when you derive a table and specify less column aliases as
columns are contained in the SELECT list. For example: the following statement will
raise the above error.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) FROM TABLE1 GROUP BY
STDNAME)ALIAS(STDNAME1)
GO
DROP TABLE TABLE1
GO

Action Required to resolve this Error:

The solution to this error is you must specify (either explicitly or implicitly) a
column name of each column of a derived table. In the above example we try to
derive a table ALIAS in which we specify only one column alias STDNAME1. Because
ALIAS has more than one column, the error is raised. By adding the proper column
alias according to the columns in the table, the above statement will execute
successfully.
USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) FROM TABLE1 GROUP BY
STDNAME)ALIAS(STDNAME1,STDID1)
GO
DROP TABLE TABLE1
GO

#11
Msg 8159, Level 16, State 1, Line 2 '%.*ls' has fewer columns than were specified
in the column list.

SQL Server Error Message:

'%.*ls' has fewer columns than were specified in the column list.

What and Why "this Error":

This error occurs when you derive a table and specify fewer column aliases as
columns are contained in the SELECT list. For example: the following statement will
raise the above error.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) FROM TABLE1 GROUP BY
STDNAME)ALIAS(STDNAME,STDID1,EXTRAALIAS)
GO
DROP TABLE TABLE1
GO

Action Required to resolve this Error:

The solution to this error is you must specify (either explicitly or implicitly) a
column name of each column of a derived table. In the above example we try to
derive a table ALIAS in which we specify three column alias. Because ALIAS has
less than three columns, the error is raised. By removing the invalid column alias,
the above statement will execute successfully.

USE tempdb
CREATE TABLE TABLE1
(STDNAME VARCHAR(50),
STDID INT
)
GO
INSERT INTO TABLE1 SELECT 'HECTOR',100
UNION ALL SELECT 'SMITH',120
UNION ALL SELECT 'HARYY',130
UNION ALL SELECT 'LARRY',180
UNION ALL SELECT 'KEVIN',109
UNION ALL SELECT 'ROBERT',170
UNION ALL SELECT 'KELVIN',210
UNION ALL SELECT 'PAUL',220
GO
SELECT * FROM(SELECT STDNAME,MAX(STDID) FROM TABLE1 GROUP BY
STDNAME)ALIAS(STDNAME1,STDID1)
GO
DROP TABLE TABLE1
GO
#12
Msg 8183, Level 16, State 1, Line 5 Only UNIQUE or PRIMARY KEY constraints can
be created on computed columns, while CHECK, FOREIGN KEY, and NOT NULL
constraints require that computed columns be persisted.

SQL Server Error Message:

Only UNIQUE or PRIMARY KEY constraints can be created on computed columns,


while CHECK, FOREIGN KEY, and NOT NULL constraints require that computed
columns be persisted.

What and Why "this Error":

This error occurs when you try to use another constraint type than a PRIMARY KEY
or UNIQUE constraint for a computed column. For example: the following statement
will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 AS COL1*10 NOT NULL
)
GO

Action Required to resolve this Error:

The solution to this error is you must remove the constraint or persist the column.
In the above example we try to create a NOT NULL constraint on the computed
column COL2. This raises the error. By removing the NOT NULL from the above
statement, it will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 AS COL1*10
)
GO
DROP TABLE TEST
GO

#13
Msg 8197, Level 16, State 4, Procedure tt, Line 1 The object '%.*ls' does not exist
or is invalid for this operation.

SQL Server Error Message:

The object '%.*ls' does not exist or is invalid for this operation.

What and Why "this Error":

This error occurs when you try to execute an operation for a non-existant object or
the operation is invalid for this type of object. For example: the following statement
will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE TRIGGER TRIGGER1 ON TEST1
FOR DELETE
AS
BEGIN
PRINT'HEY STOP YOU CANNOT DELETE THIS TABLE'
END
ROLLBACK TRANSACTION
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:


The solution to this error is the object must exist and the operation must be valid
for this type of object. In the above example we try to create a trigger for the table
TEST1. Because this table does not exist, the error is raised. By specifying the valid
table name in the above statement, it will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE TRIGGER TRIGGER1 ON TEST
FOR DELETE
AS
BEGIN
PRINT'HEY STOP YOU CANNOT DELETE THIS TABLE'
END
ROLLBACK TRANSACTION
GO
DROP TABLE TEST
GO

#14
Msg 8199, Level 16, State 1, Line 3 In EXECUTE <procname>, procname can only
be a literal or variable of type char, varchar, nchar, or nvarchar.

SQL Server Error Message:

In EXECUTE <procname>, procname can only be a literal or variable of type char,


varchar, nchar, or nvarchar.

What and Why "this Error":

This error occurs when you try to EXECUTE a variable, but this variable is not of
one of the types listed in the error message. For example: the following statement
will raise the above error.

CREATE TABLE TEST


(
COL1 INT
)
GO
INSERT INTO TEST SELECT 1
UNION ALL SELECT 10
UNION ALL SELECT 15
UNION ALL SELECT 18
UNION ALL SELECT 12
UNION ALL SELECT 120
GO
CREATE PROCEDURE TESTPROC
@VRBL INT
AS
BEGIN
SELECT * FROM TEST WHERE COL1 =@VRBL
END
GO
DECLARE @VRBL INT
SET @VRBL='TESTPROC'
EXEC @VRBL 18
GO

Action Required to resolve this Error:

The solution to this error is the variable to be executed must be of a type listed in
the error message. In the above error message we try to execute a variable of the
type INT. This raises the error. To execute the above statement we must take the
valid datatype such as char, varchar, nchar or nvarchar.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
INSERT INTO TEST SELECT 1
UNION ALL SELECT 10
UNION ALL SELECT 15
UNION ALL SELECT 18
UNION ALL SELECT 12
UNION ALL SELECT 120
GO
CREATE PROCEDURE TESTPROC
@VRBL INT
AS
BEGIN
SELECT * FROM TEST WHERE COL1 =@VRBL
END
GO
DECLARE @VRBL VARCHAR(10)
SET @VRBL='TESTPROC'
EXEC @VRBL 18
GO
DROP TABLE TEST
GO
DROP PROCEDURE TESTPROC
GO
#15
Msg 2812, Level 16, State 62, Line 3 Could not find stored procedure '%.*ls'.

SQL Server Error Message:

Could not find stored procedure '%.*ls'.

What and Why "this Error":

This error occurs when you try to execute a stored procedure which does not exists.
For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
INSERT INTO TEST SELECT 1
UNION ALL SELECT 10
UNION ALL SELECT 15
UNION ALL SELECT 18
UNION ALL SELECT 12
UNION ALL SELECT 120
GO
CREATE PROCEDURE TESTPROC
@VRBL INT
AS
BEGIN
SELECT * FROM TEST WHERE COL1 =@VRBL
END
GO
EXEC TESTPROC1 @VRBL=18
GO
DROP TABLE TEST
GO
DROP PROCEDURE TESTPROC
GO

Action Required to resolve this Error:

The solution to this error is the stored procedure must exists to execute a
procedure. In the above example we try to execute a user defined stored procedure
TESTPROC1 which was name incorrectly. By passing the valid procedure name, the
above statement will execute successfully.
USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
INSERT INTO TEST SELECT 1
UNION ALL SELECT 10
UNION ALL SELECT 15
UNION ALL SELECT 18
UNION ALL SELECT 12
UNION ALL SELECT 120
GO
CREATE PROCEDURE TESTPROC
@VRBL INT
AS
BEGIN
SELECT * FROM TEST WHERE COL1 =@VRBL
END
GO
EXEC TESTPROC @VRBL=18
GO
DROP TABLE TEST
GO
DROP PROCEDURE TESTPROC
GO

#16
Msg 163, Level 15, State 1, Line 1 The compute by list does not match the order by
list.

SQL Server Error Message:

The compute by list does not match the order by list.

What and Why "this Error":

This error occurs when you try to use ORDER BY and COMPUTE BY lists that are not
identical. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(50),
COL3 VARCHAR(50),
COL4 INT
)
GO
INSERT INTO TEST SELECT 1,'HECTOR','CM',1001
UNION ALL SELECT 10,'SMITH','GM',1002
UNION ALL SELECT 15,'PAUL','DM',1003
UNION ALL SELECT 18,'HARRY','CA',1004
UNION ALL SELECT 12,'LARRY','BCA',1005
UNION ALL SELECT 120,'KEVIN','MBA',1006
GO
SELECT COL1,COL2,COL3 FROM TEST
ORDER BY COL1,COL2
COMPUTE SUM(COL1) BY COL1,COL4
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is the COMPUTE BY is only maintained for backwards
compatibility reasons. Microsoft recommends to use Analysis Services or the
ROLLUP operator instead. The following statement will execute because the I have
made ORDER BY & COMPUTE BY lists are identical.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(50),
COL3 VARCHAR(50),
COL4 INT
)
GO
INSERT INTO TEST SELECT 1,'HECTOR','CM',1001
UNION ALL SELECT 10,'SMITH','GM',1002
UNION ALL SELECT 15,'PAUL','DM',1003
UNION ALL SELECT 18,'HARRY','CA',1004
UNION ALL SELECT 12,'LARRY','BCA',1005
UNION ALL SELECT 120,'KEVIN','MBA',1006
GO
SELECT COL1,COL2,COL3 FROM TEST
ORDER BY COL1,COL2
COMPUTE SUM(COL1) BY COL1,COL2
GO
DROP TABLE TEST
GO

#17
Msg 259, Level 16, State 1, Line 1 Ad hoc updates to system catalogs are not
allowed.

SQL Server Error Message:

Ad hoc updates to system catalogs are not allowed.

What and Why "this Error":

This error occurs when you try to run an UPDATE statement against SQL Server's
system tables. For example: the following statement will raise the above error.

UPDATE SYSOBJECTS SET name = 'HECTOR'

Action Required to resolve this Error:

The solution to this error is you should refrain from manipulating system tables as
you might render the database unusable. In SQL Server 2000 there was an
extended option that would allow running modification queries against system
tables. In SQL Server 2005 this method has been removed. Although there are still
other ways, all are unsupported and you're better off calling the SQL Server Product
Support.

#18
Msg 1077, Level 16, State 1, Line 3 INSERT into an identity column not allowed on
table variables.

SQL Server Error Message:

INSERT into an identity column not allowed on table variables.

What and Why "this Error":

This error occurs when you try to insert explicitly values into an identity column of a
table variable. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
ID int IDENTITY, CustomerID int
)
GO
DECLARE @t TABLE (ID int IDENTITY, CustomerID int)
INSERT INTO @t (ID, CustomerID)
SELECT 1, CustomerID FROM TEST
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is you cannot explicitly insert values into an identity
column of a table variable. In the above example we try to insert values into an
identity column of a table variable. This raises the error.

#19
Msg 1842, Level 16, State 1, Line 2 The file size, max size cannot be greater than
2147483647 in units of a page size. The file growth cannot be greater than
2147483647 in units of both page size and percentage.

SQL Server Error Message:

The file size, max size cannot be greater than 2147483647 in units of a page size.
The file growth cannot be greater than 2147483647 in units of both page size and
percentage.

What and Why "this Error":

This error occurs when you try to create a new database file with more than
2147483647 pages or try to extend an existing one beyond this number. For
example: the following statement will raise the above error.

CREATE DATABASE EXAMPLEDB12


USE EXAMPLEDB12
ALTER DATABASE EXAMPLEDB12
ADD FILE
(
NAME = EXAMPLEDB1,
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\
MSSQL\DATA\exampledb12.ldf',
SIZE = 2147483647MB,
MAXSIZE = 2147483647MB,
FILEGROWTH = 5MB
)
Action Required to resolve this Error:

The solution to this error is you cannot create or extend a database file beyond
2147483647 pages. In the above example we try to create a new database file with
2147483647 MB. This raises the error.

USE tempdb
CREATE DATABASE EXAMPLEDB12
GO
USE EXAMPLEDB12
GO
ALTER DATABASE EXAMPLEDB12
ADD FILE
(
NAME = EXAMPLEDB1,
FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\
MSSQL\DATA\exampledb12.ldf',
SIZE = 21MB,
MAXSIZE = 2147MB,
FILEGROWTH = 5MB
)
USE tempdb
DROP DATABASE EXAMPLEDB12
GO

#20
Msg 3044, Level 16, State 2, Line 2 Invalid zero-length device name. Reissue the
BACKUP statement with a valid device name.

SQL Server Error Message:

Invalid zero-length device name. Reissue the BACKUP statement with a valid device
name.

What and Why "this Error":

This error occurs when you try to backup a database to a media with a name of
length 0. For example: the following statement will raise the above error.

USE tempdb
CREATE DATABASE EXAMPLEDB12
GO
USE EXAMPLEDB12
GO
BACKUP DATABASE EXAMPLEDB12 TO DISK=''
GO

Action Required to resolve this Error:

The solution to this error is the media name must have a name with a length > 0
and it must be valid. In the above example we try to backup the EXAMPLEDB12
database to disk. Because we use a media name with a length of 0, the error is
raised.

USE tempdb
CREATE DATABASE EXAMPLEDB12
GO
USE EXAMPLEDB12
GO
BACKUP DATABASE EXAMPLEDB12 TO DISK='c:\example.bak'
GO
USE tempdb
DROP DATABASE EXAMPLEDB12
GO

#21
Msg 15122, Level 16, State 1, Line 2 The CHECK_EXPIRATION option cannot be
used when CHECK_POLICY is OFF.

SQL Server Error Message:

The CHECK_EXPIRATION option cannot be used when CHECK_POLICY is OFF.

What and Why "this Error":

This error occurs when attempting to use the CHEKC_EXPIRATION = ON Option in a


CREATE LOGIN statement, while the CHECK_POLICY Option is set to OFF. For
example: the following statement will raise the above error.

USE Master;
CREATE LOGIN TESTLOGIN
WITH PASSWORD = 'TEST@123',
CHECK_POLICY = OFF,
CHECK_EXPIRATION = ON;
GO

Action Required to resolve this Error:

The solution to this error is the CHECK_POLICY must be set to ON for the
CHECK_EXPIRATION option to make sense at all. In the above example we try to
create a login for which the CHEKC_POLICY option is set to OFF, while
CHECK_EXPIRATION is set to ON. This raises the error. By turning CHEKC_POLICY
option to ON, the above statement will execute successfully.

USE Master;
CREATE LOGIN TESTLOGIN
WITH PASSWORD = 'TEST@123',
CHECK_POLICY = ON,
CHECK_EXPIRATION = ON;
GO

#22
Msg 15416, Level 16, State 1, Procedure sp_dbcmptlevel, Line 70 Usage:
sp_dbcmptlevel [dbname [, compatibilitylevel]]

SQL Server Error Message:

Usage: sp_dbcmptlevel [dbname [, compatibilitylevel]]

What and Why "this Error":

This error occurs when you try to execute the system procedure sp_dbcmptlevel
with wrong parameters. For example: the following statement will raise the above
error.

USE tempdb
CREATE DATABASE EXAMPLEDB12
GO
USE EXAMPLEDB12
GO
USE EXAMPLEDB12
EXEC sp_dbcmptlevel 'EXAMPLEDB12', 50
GO
USE tempdb
DROP DATABASE EXAMPLEDB12
GO
Action Required to resolve this Error:

The solution to this error is you must provide valid values for the expected
parameters. In the above example we try to set the compatibility level for the
EXAMPLEDB12database to 50. Since this is no valid value, the error is raised. If you
look at the error generated you can see the compatibility level that are 80, 90 or
100. You can use one out of these levels & as result the above statement will
execute successfully.

USE tempdb
CREATE DATABASE EXAMPLEDB12
GO
USE EXAMPLEDB12
GO
USE EXAMPLEDB12
EXEC sp_dbcmptlevel 'EXAMPLEDB12', 90
GO
USE tempdb
DROP DATABASE EXAMPLEDB12
GO

#23
Msg 15102, Level 16, State 1, Procedure sp_bindefault, Line 166
Cannot bind a default to an identity column.

SQL Server Error Message:

Cannot bind a default to an identity column.

What and Why "this Error":

This error occurs when you try bind a default that you've create with a CREATE
DEFAULT command to a column with the identity property. For example: the
following statement will raise the above error.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT IDENTITY NOT NULL
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC sp_bindefault 'TESTDEFAULT', 'TEST.COL1'
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error you can not bind a default to such a column. In the above
example we try to bind the default TESTDEFAULT to the column COL1. Because this
column is a column with the identity property, the error is raised.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC sp_bindefault 'TESTDEFAULT', 'TEST.COL1'
GO
DROP TABLE TEST
GO
DROP DEFAULT TESTDEFAULT
GO

#24
Msg 15107, Level 16, State 1, Procedure sp_bindrule, Line 143 Cannot bind a rule
to a computed column or to a column of data type text, ntext, image, timestamp,
varchar(max), nvarchar(max), varbinary(max), xml or sqlclr type.

SQL Server Error Message:

Cannot bind a rule to a computed column or to a column of data type text, ntext,
image, timestamp, varchar(max), nvarchar(max), varbinary(max), xml or sqlclr
type.

What and Why "this Error":

This error occurs when you try bind a rule to one of the in the message mentioned
data types. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 TEXT
)
GO
CREATE RULE RULE1 AS @COL1 IN('HECTOR','PAUL','KEVIN')
GO
SP_BINDRULE 'RULE1','TEST.COL1'
GO
DROP TABLE TEST
DROP RULE RULE1
GO

Action Required to resolve this Error:

The solution to this error you can not bind a rule to a BLOB data type. CREATE
RULE and sp_bindrule are deprecated constructs and will be removed in a future
SQL Server version. Use CHECK constraints instead. In the above example we try
use the TEXT datatype for column COL1 of table TEST, though TEXT datatype is not
supported by the RULE. This causes the error.

USE tempdb
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
CREATE RULE RULE1 AS @COL1 IN('HECTOR','PAUL','KEVIN')
GO
SP_BINDRULE 'RULE1','TEST.COL1'
GO
DROP TABLE TEST
DROP RULE RULE1
GO

#25
Msg 16917, Level 16, State 1, Line 4 Cursor is not open.

SQL Server Error Message:

Cursor is not open.

What and Why "this Error":


This error occurs when you try to use a cursor that has not been opened yet. For
example: the following statement will raise the above error.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
FETCH NEXT FROM TESTCURSOR
DEALLOCATE TESTCURSOR
GO
USE tempdb
DROP DATABASE TESTING
GO

Action Required to resolve this Error:

The solution to this error is you must open the cursor before you can use it. In the
above example we try to use the cursor TESTCURSOR. Because this cursor hasn't
been opened yet the error is raised. If you open the cursor before you use it, the
above statement will execute successfully.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
OPEN TESTCURSOR
FETCH NEXT FROM TESTCURSOR
DEALLOCATE TESTCURSOR
GO
USE tempdb
DROP DATABASE TESTING
GO
#26
Msg 16916, Level 16, State 1, Line 4 A cursor with the name '%.*ls' does not exist.

SQL Server Error Message:

A cursor with the name '%.*ls' does not exist.

What and Why "this Error":

This error occurs when you try to use a non-existing cursor. For example: the
following statement will raise the above error.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
OPEN TESTCURSOR
FETCH NEXT FROM TESTCURSOR
DEALLOCATE TESTCURSOR
GO
USE tempdb
DROP DATABASE TESTING
GO

Action Required to resolve this Error:

The solution to this error is you can only refer to valid and existing cursors. You
must either declare the cursor before you can use it. In the above example we try
to use the cursor TESTCURSOR. Because this cursor hasn't been declared yet the
error is raised. By declaring TESTCURSOR in the above statement, the above
statement will execute successfully.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
OPEN TESTCURSOR
FETCH NEXT FROM TESTCURSOR
DEALLOCATE TESTCURSOR
GO
USE tempdb
DROP DATABASE TESTING
GO

#27
Msg 16915, Level 16, State 1, Line 8 A cursor with the name '%.*ls' already exists.

SQL Server Error Message:

A cursor with the name '%.*ls' already exists.

What and Why "this Error":

This error occurs when you try to declare a cursot multiple times. For example: the
following statement will raise the above error.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
OPEN TESTCURSOR
FETCH NEXT FROM TESTCURSOR
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
DEALLOCATE TESTCURSOR
GO
USE tempdb
DROP DATABASE TESTING
GO
Action Required to resolve this Error:

The solution to this error is you must first deallocate the cursor before you can
reuse it. In the above example we try to declare the cursor TESTCURSOR more
than once without deallocating it first. This raises the error.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
CREATE TABLE TEST
(
COL1 VARCHAR(50)
)
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
OPEN TESTCURSOR
FETCH NEXT FROM TESTCURSOR
DEALLOCATE TESTCURSOR
GO
DECLARE TESTCURSOR CURSOR READ_ONLY FOR
SELECT * FROM TEST
DEALLOCATE TESTCURSOR
GO
USE tempdb
DROP DATABASE TESTING
GO

#28
Msg 8107, Level 16, State 1, Line 1 IDENTITY_INSERT is already ON for table
'%.*ls.%.*ls.%.*ls'. Cannot perform SET operation for table '%.*ls'.

SQL Server Error Message:

IDENTITY_INSERT is already ON for table '%.*ls.%.*ls.%.*ls'. Cannot perform SET


operation for table '%.*ls'.

What and Why "this Error":

This error occurs when you try to set IDENTITY_INSERT to on, but this setting is
already activated. For example: the following statement will raise the above error.
USE tempdb
CREATE TABLE TEST
(
COL1 INT IDENTITY
)
GO
CREATE TABLE TEST2
(
COL2 INT IDENTITY
)
GO
SET IDENTITY_INSERT TEST ON
SET IDENTITY_INSERT TEST2 ON
GO
DROP TABLE TEST
DROP TABLE TEST2
GO

Action Required to resolve this Error:

The solution to this error is IDENTITY_INSERT can only be set to on for one table in
a database at a time. It must be turned off, before it can be turned on again for a
different table. In the above example we try to set IDENTITY_INSERT to on for the
table TEST and TEST2. This raises the error. The following statement will execute
successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT IDENTITY
)
GO
CREATE TABLE TEST2
(
COL2 INT IDENTITY
)
GO
SET IDENTITY_INSERT TEST ON
GO
SET IDENTITY_INSERT TEST OFF
SET IDENTITY_INSERT TEST2 ON
GO
SET IDENTITY_INSERT TEST OFF
GO
DROP TABLE TEST
DROP TABLE TEST2
GO
#29
Msg 15143, Level 16, State 1, Line 27 '%s' is not a valid option for the
@updateusage parameter. Enter either 'true' or 'false'.

SQL Server Error Message:

'%s' is not a valid option for the @updateusage parameter. Enter either 'true' or
'false'.

What and Why "this Error":

This error occurs when you try to use an invalid option for the @updateusage
parameter of the sp_spaceused procedure. For example: the following statement
will raise the above error.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
GO
CREATE TABLE TEST
(
COL1 INT
)
GO
USE TESTING
EXEC sp_spaceused @objname = N'TEST', @updateusage = 'TUER'
USE tempdb
GO
DROP DATABASE TESTING
GO

Action Required to resolve this Error:

The solution to this error is the valid values for the @updateusage parameter are
only 'TRUE' and 'FALSE'. in the above example we try to execute the sp_spaceused
procedure with the invalid value ‘TEUR’ for the @updateusage parameter. This
raises the error. The following statement will execute successfully.

USE tempdb
CREATE DATABASE TESTING
GO
USE TESTING
GO
CREATE TABLE TEST
(
COL1 INT
)
GO
USE TESTING
EXEC sp_spaceused @objname = N'TEST', @updateusage = 'TRUE'
USE tempdb
GO
DROP DATABASE TESTING
GO

#30
Msg 15109, Level 16, State 1, Procedure sp_changedbowner, Line 22 Cannot
change the owner of the master, model, tempdb or distribution database.

SQL Server Error Message:

Cannot change the owner of the master, model, tempdb or distribution database.

What and Why "this Error":

This error occurs when you try to change the owner of one in the message
mentioned databases. For example: the following statement will raise the above
error.

USE master
EXEC sp_changedbowner 'TESTLOGIN'

Action Required to resolve this Error:

The solution to this error is you cannot change the owner of these databases. In the
above example we try to change the owner of the master database. This raises the
error. In the following statement I will use the EXAMPLEDB database to change it’s
ownership to a user TESTLOGIN.

USE EXAMPLEDB
EXEC sp_changedbowner 'TESTLOGIN'
#31
Msg 15103, Level 16, State 1, Procedure sp_bindefault, Line 178 Cannot bind a
default to a column created with or altered to have a default value.

SQL Server Error Message:

Cannot bind a default to a column created with or altered to have a default value.

What and Why "this Error":

This error occurs when you try to bind a via CREATE DEFAULT generated default to
a column that has already a default constraint defined. For example: the following
statement will raise the above error.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT NOT NULL CONSTRAINT DFLTCNSTRNT DEFAULT(0)
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC sp_bindefault 'TESTDEFAULT', 'TEST.COL1';
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is each column can only have one default value. In the
above example we try to bind the default TESTDEFAULT to the column COL1.
Because this column already has a default constraint defined on it, the error is
raised. Either you have to remove the default constraint at the time of creation of
table or you should remove the CREATE DEFAULT statement from the above
statement.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT NOT NULL
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC sp_bindefault 'TESTDEFAULT', 'TEST.COL1';
GO
DROP TABLE TEST
DROP DEFAULT TESTDEFAULT
GO

OR

USE tempdb;
CREATE TABLE TEST
(
COL1 INT NOT NULL CONSTRAINT DFLTCNSTRNT DEFAULT(0)
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
DROP TABLE TEST
DROP DEFAULT TESTDEFAULT
GO

#32
Msg 15101, Level 16, State 1, Procedure sp_bindefault, Line 158 Cannot bind a
default to a computed column or to a column of data type timestamp,
varrchar(max), nvarchar(max), varbinary(max), xml or sqlclr type.

SQL Server Error Message:

Cannot bind a default to a computed column or to a column of data type


timestamp, varchar(max), nvarchar(max), varbinary(max), xml or sqlclr

What and Why "this Error":

This error occurs when try to bind a via CREATE DEFAULT generated default to a
column that has an invalid datatype for a default or is a computed column. For
example: the following statement will raise the above error.

USE tempdb;
CREATE TABLE TEST
(
COL1 TIMESTAMP NOT NULL
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC SP_BINDEFAULT 'TESTDEFAULT','TEST.COL1'
DROP TABLE TEST
GO
DROP DEFAULT TESTDEFAULT
GO

Action Required to resolve this Error:

The solution to this error is the column must have a valid datatype. In the above
example we try to bind the default TESTDEFAULT to a column of the type
TIMESTAMP. This raises the error. In the following statement I have used INT
datatype & as result the above statement executes successfully.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT NOT NULL
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC SP_BINDEFAULT 'TESTDEFAULT','TEST.COL1'
DROP TABLE TEST
GO
DROP DEFAULT TESTDEFAULT
GO

#33
Msg 15100, Level 16, State 1, Procedure sp_bindefault, Line 80 Usage:
sp_bindefault defaultname, objectname [, 'futureonly']

SQL Server Error Message:

Usage: sp_bindefault defaultname, objectname [, 'futureonly']

What and Why "this Error":

This error occurs when you try to execute the sp_bindefault procedure iwth an
invalid syntax. For example: the following statement will raise the above error.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT NOT NULL
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC SP_BINDEFAULT'HELLO', 'TESTDEFAULT','TEST.COL1'
DROP TABLE TEST
GO
DROP DEFAULT TESTDEFAULT
GO

Action Required to resolve this Error:

The solution to this error is the syntax must be valid. In the above example we try
to execute sp_bindefault with invalid arguments in incorrect order. This raises the
error. By removing the invalid parameters from the above statement, it will execute
successfully.

USE tempdb;
CREATE TABLE TEST
(
COL1 INT NOT NULL
)
GO
CREATE DEFAULT TESTDEFAULT AS 10;
Go
EXEC SP_BINDEFAULT 'TESTDEFAULT','TEST.COL1'
DROP TABLE TEST
GO
DROP DEFAULT TESTDEFAULT
GO

#34
Msg 179, Level 15, State 1, Line 3 Cannot use the OUTPUT option when passing a
constant to a stored procedure.

SQL Server Error Message:

Cannot use the OUTPUT option when passing a constant to a stored procedure.

What and Why "this Error":

This error occurs when you try to execute a stored procedure with an OUTPUT
parameter, but pass a constant to that parameter. For example: the following
statement will raise the above error.

CREATE PROCEDURE TESTPROC


@VRBL INT OUTPUT
AS
BEGIN
SELECT @VRBL
END
DECLARE @VRBL2 INT
EXEC TESTPROC 10 OUTPUT
DROP PROC TESTPROC
GO

Action Required to resolve this Error:

The solution to this error is you cannot pass a constant to a procedure for a
parameter marked as OUTPUT parameter. In the above example we try to call the
stored procedure TESTPROC, for which the first parameter is marked as OUTPUT
parameter. In the call however the constant 10 is passed. This raises the error. By
removing the OUTPUT from the above statement, it will execute successfully.

CREATE PROCEDURE TESTPROC


@VRBL INT OUTPUT
AS
BEGIN
SELECT @VRBL
END
DECLARE @VRBL2 INT
EXEC TESTPROC 10
DROP PROC TESTPROC
GO

#35
Msg 181, Level 15, State 1, Line 1 Cannot use the OUTPUT option in a DECLARE,
CREATE AGGREGATE or CREATE FUNCTION statement.

SQL Server Error Message:

Cannot use the OUTPUT option in a DECLARE, CREATE AGGREGATE or CREATE


FUNCTION statement.

What and Why "this Error":

This error occurs when you try to use the OUTPUT option in a DECLARE statement
or in a CREATE FUNCTION statement. For example: the following statement will
raise the above error.
USE tempdb
GO
CREATE FUNCTION DBO.TEST(@VRBL INT OUTPUT)
RETURNS INT
AS
BEGIN
RETURN(@VRBL*10)
END
GO

Action Required to resolve this Error:

The solution to this error is the OUTPUT option can only be used inside a stored
procedure. In the above example we try to use the OUTPUT option in a DECLARE
statement. This raises the error. By removing the OUTPUT from the above
statement, it will execute successfully & gives the result 150.

USE tempdb
GO
CREATE FUNCTION DBO.TEST(@VRBL INT )
RETURNS INT
AS
BEGIN
RETURN(@VRBL*10)
END
GO
DECLARE @VRBL INT SET @VRBL=DBO.TEST(15)
PRINT @VRBL
GO
DROP FUNCTION TEST
GO

#36
Msg 298, Level 16, State 1, Line 4 The conversion from datetime data type to
smalldatetime data type resulted in a smalldatetime overflow error.

SQL Server Error Message:

The conversion from datetime data type to smalldatetime data type resulted in a
smalldatetime overflow error.

What and Why "this Error":


This error occurs when you try to convert a datetime value into a smalldatetime
value, but this value is outside the range of valid values for the smalldatetime type.
For example: the following statement will raise the above error.

DECLARE @VRBL DATETIME;


SET @VRBL = '99881102';
SELECT CAST (@VRBL AS SMALLDATETIME)

Action Required to resolve this Error:

The solution to this error is the value must be within the range of valid values for
the smalldatetime type. In the above example we try to convert the datetime value
'9988-11-02' into a value of type smalldatetime. Because the value is outside the
range of valid smalldatetime values, the error is raised. The following statement will
execute successfully.

DECLARE @VRBL DATETIME;


SET @VRBL = '19881102';
SELECT CAST (@VRBL AS SMALLDATETIME)

#37
Msg 308, Level 16, State 1, Line 3 Index '%.*ls' on table '%.*ls' (specified in the
FROM clause) does not exist.

SQL Server Error Message:

Index '%.*ls' on table '%.*ls' (specified in the FROM clause) does not exist.

What and Why "this Error":

This error occurs when you try to force the usage of a non-existing index. For
example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
SELECT * FROM TEST WITH(INDEX=CLSTRDINDX)
GO
DROP TABLE TEST
GO
Action Required to resolve this Error:

The solution to this error is the index must exist before it can be used. In the above
example we try to force SQL Server to use the index 'CLSTRDINDX'. Because this
index does not exist, the error is raised. The following statement will execute
because I have created a clustered index.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE CLUSTERED INDEX CLSTRDINDX ON TEST(COL1)
GO
SELECT * FROM TEST WITH(INDEX=CLSTRDINDX)
GO
DROP TABLE TEST
GO

#38
Msg 309, Level 16, State 1, Line 1 Cannot use index "%.*ls" on table "%.*ls" in a
hint. XML indexes are not allowed in hints.

SQL Server Error Message:

Cannot use index "%.*ls" on table "%.*ls" in a hint. XML indexes are not allowed in
hints.

What and Why "this Error":

This error occurs when you try to force the usage of an XML index in a hint. For
example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT PRIMARY KEY,
COL2 XML
)
GO
CREATE PRIMARY XML INDEX XMLINDX ON TEST(COL2)
GO
SELECT * FROM TEST WITH(INDEX=XMLINDX)
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is you cannot force SQL Server to use an XML index in a
hint. In the above example we try to force SQL Server to use the index ‘XMLINDX’.
Because this index is an XML index, the error is raised. You can use the valid data
type for further hints. The following statement will execute because I have used the
INT data type for the above statement.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE CLUSTERED INDEX CLSTRDINDX ON TEST(COL1)
GO
SELECT * FROM TEST WITH(INDEX=CLSTRDINDX)
GO
DROP TABLE TEST
GO

#39
Msg 316, Level 16, State 1, Line 11 The index ID %d on table "%.*ls" (specified in
the FROM clause) is disabled or resides in a filegroup which is not online.

SQL Server Error Message:

The index ID %d on table "%.*ls" (specified in the FROM clause) is disabled or


resides in a filegroup which is not online.

What and Why "this Error":

This error occurs when you try to force the usage of an index via the internal index
in a hint, but this index is either disabled or resides in an offline filegroup. For
example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE INDEX INDX ON TEST(COL1)
GO
ALTER INDEX INDX ON TEST DISABLE
GO
SELECT * FROM TEST WITH(INDEX=2)
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is the index that you are trying to force SQL Server to use
must be enabled and in an online filegroup. In the above example we try to force
SQL Server to use the index INDX via the internal index ID. Because this index is
deactivated, the error is raised. By removing the DISABLE statement from the
above statement it will execute.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE INDEX INDX ON TEST(COL1)
GO
SELECT * FROM TEST WITH(INDEX=2)
GO
DROP TABLE TEST
GO

#40
Msg 315, Level 16, State 1, Line 11 The index ID %d on table "%.*ls" (specified in
the FROM clause) is disabled or resides in a filegroup which is not online.

SQL Server Error Message:

The index ID %d on table "%.*ls" (specified in the FROM clause) is disabled or


resides in a filegroup which is not online.

What and Why "this Error":


This error occurs when you try to force the usage of an index via the internal index
in a hint, but this index is either disabled or resides in an offline filegroup. For
example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE INDEX INDX ON TEST(COL1)
GO
ALTER INDEX INDX ON TEST DISABLE
GO
SELECT * FROM TEST WITH(INDEX=INDX)
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is the index that you are trying to force SQL Server to use
must be enabled and in an online filegroup. In the above example we try to force
SQL Server to use the index INDX. Because this index is deactivated, the error is
raised. By removing the DISABLE statement from the above statement it will
execute.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE INDEX INDX ON TEST(COL1)
GO
SELECT * FROM TEST WITH(INDEX=2)
GO
DROP TABLE TEST
GO

#41
Msg 331, Level 16, State 1, Line 2 The target table '%.*ls' of the OUTPUT INTO
clause cannot have any enabled triggers.
SQL Server Error Message:

The target table '%.*ls' of the OUTPUT INTO clause cannot have any enabled
triggers.

What and Why "this Error":

This error occurs when you try to use the OUTPUT INTO clause for a target table
which has triggers enabled. For example: the following statement will raise the
above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TABLE TEST2
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TRIGGER TRIGGER1 ON TEST2
FOR INSERT
AS
SELECT 10;
GO
INSERT INTO TEST
OUTPUT INSERTED.COL1,
INSERTED.COL2
INTO TEST2 SELECT 1001,'HECTOR'
GO
DROP TABLE TEST
DROP TABLE TEST2
GO

Action Required to resolve this Error:

The solution to this error is the target table of the OUTPUT INTO clause cannot have
enabled triggers. In the above example we try to insert data into the table TEST2
via the OUTPUT INTO clause. Because TEST2 has enabled triggers, the error is
raised. By dropping the trigger from the above statement it will execute
successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TABLE TEST2
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TRIGGER TRIGGER1 ON TEST2
FOR INSERT
AS
SELECT 10;
GO
DROP TRIGGER TRIGGER1
GO
INSERT INTO TEST
OUTPUT INSERTED.COL1,
INSERTED.COL2
INTO TEST2 SELECT 1001,'HECTOR'
GO
DROP TABLE TEST
DROP TABLE TEST2
GO

#42
Msg 332, Level 16, State 1, Line 6 The target table '%.*ls' of the OUTPUT INTO
clause cannot be on either side of a (primary key, foreign key) relationship. Found
reference constraint '%ls'.

SQL Server Error Message:

The target table '%.*ls' of the OUTPUT INTO clause cannot be on either side of a
(primary key, foreign key) relationship. Found reference constraint '%ls'.

What and Why "this Error":

This error occurs when you try to use the OUTPUT INTO clause for a target table
that appears on either side of a PRIMARY KEY - FOREIGN KEY relationship. For
example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TABLE TEST2
(
COL1 INT PRIMARY KEY,
COL2 VARCHAR(10)
)
GO
CREATE TABLE TEST3
(
COL1 INT CONSTRAINT FRNKY FOREIGN KEY REFERENCES TEST2(COL1),
COL2 VARCHAR(10)
)
GO
INSERT INTO TEST2
OUTPUT INSERTED.COL1,
INSERTED.COL2
INTO TEST3 SELECT 1001,'HECTOR'
GO
DROP TABLE TEST
DROP TABLE TEST3
DROP TABLE TEST2
GO

Action Required to resolve this Error:

The solution to this error is the target table of the OUTPUT INTO clause cannot be
on either side of a PRIMARY KEY - FOREIGN KEY relationship. In the above example
we try to insert data into the table TEST2 via the OUTPUT INTO clause. Because
TEST2 appears on the PRIMARY KEY side of a PRIMARY KEY - FOREIGN KEY
relation, the error is raised. By removing the PRIMARY KEY - FOREIGN KEY relation,
the above statement will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TABLE TEST2
(
COL1 INT ,
COL2 VARCHAR(10)
)
GO
CREATE TABLE TEST3
(
COL1 INT ,
COL2 VARCHAR(10)
)
GO
INSERT INTO TEST2
OUTPUT INSERTED.COL1,
INSERTED.COL2
INTO TEST3 SELECT 1001,'HECTOR'
GO
DROP TABLE TEST
DROP TABLE TEST3
DROP TABLE TEST2
GO

#43
Msg 494, Level 16, State 1, Line 4 The TABLESAMPLE clause can only be used with
local tables.

SQL Server Error Message:

The TABLESAMPLE clause can only be used with local tables.

What and Why "this Error":

This error occurs when you try to use the TABLESAMPLE clause with a non-local
table. For example: the following statement will raise the above error.

DECLARE @VRBL int;


SET @VRBL = 100;
SELECT * FROM INFORMATION_SCHEMA.TABLES TABLESAMPLE (@VRBL ROWS);
GO

Action Required to resolve this Error:

The solution to this error is the TABLESAMPLE clause can only be used with local
tables. In the above example we try to use the TABLESAMPLE clause for the
INFORMATION_SCHEMA.TABLES view. This raises the error. You can create a local
table & then use TABLESAMPLE as shown in the below statement.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
INSERT INTO TEST SELECT 1001,'HECTOR'
UNION ALL SELECT 1002,'PAUL'
UNION ALL SELECT 1003,'HARRY'
UNION ALL SELECT 1004,'KEVIN'
UNION ALL SELECT 1005,'LARRY'
UNION ALL SELECT 1006,'KELVIN'
UNION ALL SELECT 1007,'STEVE'
UNION ALL SELECT 1008,'VICTOR'
GO
SELECT * FROM TEST TABLESAMPLE (4 ROWS);
GO
DROP TABLE TEST
GO

#44
Msg 1007, Level 15, State 1, Line 3 The %S_MSG '%.*ls' is out of the range for
numeric representation (maximum precision 38).

SQL Server Error Message:

The %S_MSG '%.*ls' is out of the range for numeric representation (maximum
precision 38).

What and Why "this Error":

This error occurs when a numeric is value outside the range for the representation
of numerical values. For example: the following statement will raise the above
error.

DECLARE @FLTVRBL float;


SET @FLTVRBL = 0.000000000000000000000000000000000000009
SELECT @FLTVRBL;

Action Required to resolve this Error:

The solution to this error is the value must be within the valid range for numerical
representation. In the above example we try to assign a value that is outside the
range for numerical representation to the variable @FLTVRBL. So as the error says
maximum precision is 38 & in our case it was 39 after the ‘0.’, this is the cause of
error.

DECLARE @FLTVRBL float;


SET @FLTVRBL = 0.00000000000000000000000000000000000009
SELECT @FLTVRBL;
#45
Msg 1034, Level 15, State 1, Procedure, Line 2 Syntax error: Duplicate specification
of the action "%.*s" in the trigger declaration.

SQL Server Error Message:

Syntax error: Duplicate specification of the action "%.*s" in the trigger declaration.

What and Why "this Error":

This error occurs when in a trigger definition the event for which the trigger should
fire is specified more than once. For example: the following statement will raise the
above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TRIGGER TRIGGER1 ON TEST
FOR INSERT,INSERT
AS
SELECT 10;
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is the duplicate event specification must be removed from
the trigger definition. In the above example we specify the INSERT event for the
trigger more than once. This raises the error. By removing the extra INSERT event
from the above statement, it will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT,
COL2 VARCHAR(10)
)
GO
CREATE TRIGGER TRIGGER1 ON TEST
FOR INSERT
AS
SELECT 10;
GO
DROP TABLE TEST
GO

#46
Msg 1059, Level 15, State 1, Procedure, Line 0 Cannot set or reset the 'parseonly'
option within a procedure or function.

SQL Server Error Message:

Cannot set or reset the ' PARSEONLY ' option within a procedure or function.

What and Why "this Error":

This error occurs when you try to use the 'PARSEONLY' option in a procedure or
function. For example: the following statement will raise the above error.

CREATE PROCEDURE TESTPROC


AS
SET NOCOUNT ON;
SET PARSEONLY OFF;
SELECT 10;
GO

Action Required to resolve this Error:

The solution to this error is you cannot use the 'PARSEONLY' option in a procedure
or function. I n the above example we try to use the ' PARSEONLY ' option in the
procedure TESTPROC. This raises the error. By removing it the above statement will
execute successfully.

CREATE PROCEDURE TESTPROC


AS
SET NOCOUNT ON;
SELECT 10;
GO
DROP PROC TESTPROC
GO
#47
Msg 1084, Level 15, State 1, Procedure, Line 2 '%.*ls' is an invalid event type.

SQL Server Error Message:

'%.*ls' is an invalid event type.

What and Why "this Error":

This error occurs when you specify an invalid event in a trigger. For example: the
following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE TRIGGER TRIGGER1 ON TEST2
FOR INSERTED
AS
SELECT 10;
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is valid events in a trigger are INSERT, UPDATE, and
DELETE. In the above example we try to create a trigger for the event 'inserted'.
This raises the error. By using the valid events, the above statement will execute
successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT
)
GO
CREATE TRIGGER TRIGGER1 ON TEST
FOR INSERT
AS
SELECT 10;
GO
DROP TABLE TEST
GO

#48
Msg 1757, Level 16, State 0, Line 4 Column '%.*ls.%.*ls' is not of same collation
as referencing column '%.*ls.%.*ls' in foreign key '%.*ls'.

SQL Server Error Message:

Column '%.*ls.%.*ls' is not of same collation as referencing column '%.*ls.%.*ls'


in foreign key '%.*ls'.

What and Why "this Error":

This error occurs when you try to define a foreign key constraint on columns having
different collations. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST (COL1 varchar(50) COLLATE Azeri_Latin_100_CI_AI_WS NOT NULL
PRIMARY KEY);
GO
CREATE TABLE TEST2 (COL1 varchar(50) COLLATE Bosnian_Cyrillic_100_CI_AI_KS_WS
CONSTRAINT FRNK FOREIGN KEY REFERENCES TEST (COL1))
GO
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is columns in a foreign key constraint must be of the same
collation. In the above example we try to define a foreign key constraint on
columns having a different collation. This raises the error. By using the same
collation in the foreign key constraint, the above statement will execute
successfully.

USE tempdb
CREATE TABLE TEST (COL1 varchar(50) COLLATE Bosnian_Cyrillic_100_CI_AI_KS_WS
NOT NULL PRIMARY KEY);
GO
CREATE TABLE TEST2 (COL1 varchar(50) COLLATE Bosnian_Cyrillic_100_CI_AI_KS_WS
CONSTRAINT FRNK FOREIGN KEY REFERENCES TEST (COL1))
GO
DROP TABLE TEST2
DROP TABLE TEST
GO
You can check all the collations in SQL Server by using the following command.

SELECT * FROM FN_HELPCOLLATIONS()

#49
Msg 1761, Level 16, State 0, Line 3 Cannot create the foreign key "%.*ls" with the
SET NULL referential action, because one or more referencing columns are not
nullable.

SQL Server Error Message:

Cannot create the foreign key "%.*ls" with the SET NULL referential action, because
one or more referencing columns are not nullable.

What and Why "this Error":

This error occurs when you try to create a foreign key constraint with the referential
SET NULL action, but the referencing column(s) is defined as non-nullable. For
example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NOT NULL PRIMARY KEY
)
GO
CREATE TABLE TEST2
(
COL1 INT NOT NULL PRIMARY KEY CONSTRAINT FRNKY FOREIGN KEY REFERENCES
TEST(COL1) ON DELETE SET NULL
)
GO
DROP TABLE TEST
DROP TABLE TEST2
GO

Action Required to resolve this Error:

The solution to this error is either the referential action must be changed or the
referencing column must be changed to allow NULL values. In the above example
we try to create a foreign key constraint with the referential SET NULL action on
TEST2 (COL1) that references TEST (COL1). Because COL1 is defined as NOT NULL,
the error is raised. By removing the ON DELETE from the above statement, it will
execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NOT NULL PRIMARY KEY
)
GO
CREATE TABLE TEST2
(
COL1 INT NOT NULL PRIMARY KEY CONSTRAINT FRNKY FOREIGN KEY REFERENCES
TEST(COL1)
)
GO
DROP TABLE TEST2
DROP TABLE TEST
GO

#50
Msg 1762, Level 16, State 0, Line 3 Cannot create the foreign key "%.*ls" with the
SET DEFAULT referential action, because one or more referencing not-nullable
columns lack a default constraint.

SQL Server Error Message:

Cannot create the foreign key "%.*ls" with the SET DEFAULT referential action,
because one or more referencing not-nullable columns lack a default constraint.

What and Why "this Error":

This error occurs when you try to create a foreign key constraint with the referential
SET DEFAULT action, but the referencing column has no DEFAULT constraint
defined on it. For example: the following statement will raise the above error.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NOT NULL PRIMARY KEY
)
GO
CREATE TABLE TEST2
(
COL1 INT NOT NULL PRIMARY KEY CONSTRAINT FRNKY FOREIGN KEY REFERENCES
TEST(COL1) ON DELETE SET DEFAULT
)
GO
DROP TABLE TEST2
DROP TABLE TEST
GO

Action Required to resolve this Error:

The solution to this error is either the referential action must be changed or the
referencing column must have a DEFAULT constraint defined on it. In the above
example we try to create a foreign key constraint with the referential SET DEFAULT
action on TEST2 (COL1) that references TEST (COL1). Because COL1 has no
DEFAULT constraint defined, the error is raised. By removing the ON DELETE from
the above statement, it will execute successfully.

USE tempdb
CREATE TABLE TEST
(
COL1 INT NOT NULL PRIMARY KEY
)
GO
CREATE TABLE TEST2
(
COL1 INT NOT NULL PRIMARY KEY CONSTRAINT FRNKY FOREIGN KEY REFERENCES
TEST(COL1)
)
GO
DROP TABLE TEST2
DROP TABLE TEST
GO

You might also like