%ls %.*ls failed because one or more objects access this column.

Error Message:
Msg 4922, Level 16, State 9, Line 1
%ls %.*ls failed because one or more objects access this column.

Severity level:
16.

Description:
This error message appears when you try to drop a column via ALTER TABLE DROP COLUMN, however other objects, such as constraints, do reference the column.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Errors of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. The statement cannot be executed this way. You must first drop the referencing objects before the column can be dropped.

Versions:
All versions of SQL Server.

Example(s):
USE tempdb;
GO
IF OBJECT_ID(‘tempdb..#t’) > 0
 DROP TABLE #t
GO
CREATE TABLE #t
(
 id INT PRIMARY KEY
)
GO
ALTER TABLE #t DROP COLUMN id

Remarks:
In the above example we try to drop the column c1 of the table #t. Because there is a PRIMARY KEY constraint that accesses the column c1, the error is raised.

In order to successfully complete this statement, you first need to drop the PRIMARY KEY constraint, before you can drop the column.

]]>

Leave a comment

Your email address will not be published.