Skip to content

SQL Server Error Messages - Msg 128

Error Message

Server: Msg 128, Level 15, State 1, Line 1
The name <Column Name> is not permitted in this context. 
Only constants, expressions, or variables allowed here. 
Column names are not permitted.

Causes

One cause of this error message is when using a column as the DEFAULT value of another column when a table is created.

To illustrate, here’s a CREATE TABLE statement wherein the DEFAULT value assigned to one of the columns, the ‘New Balance’ column, is based on another column, the 'Previous Balance' and 'Amount' columns.

CREATE TABLE [dbo].[Deposit] (
[Account Number] VARCHAR(20),
[Previous Balance] MONEY,
[Amount] MONEY,
[New Balance] MONEY DEFAULT ([Previous Balance] + [Amount])
)

Executing this CREATE TABLE statement will generate the following error message:

Server: Msg 128, Level 15, State 1, Line 5
The name 'Previous Balance' is not permitted in this context.
Only constants, expressions, or variables allowed here.
Column names are not permitted.

Solution / Work Around

To avoid this error from happening, when setting the DEFAULT value of a column make sure to use only constants, expressions or variables and not another column. System functions such as GETDATE() and NEWID() can be used as DEFAULT values.

In the example shown above, another way to overcome this error is with the use of computed columns. Here’s how the CREATE TABLE statement will look like with a computed column for the 'New Balance':

CREATE TABLE [dbo].[Deposit] (
[Account Number] VARCHAR(20),
[Previous Balance] MONEY,
[Amount] MONEY,
[New Balance] AS [Previous Balance] + [Amount]
)