Invalid SQL data type "

Why is SQL Server Express 2008 giving me this error?

CREATE TABLE model (
name varchar(3),
desc varchar(25)
)


0x80040E14, Minor Error 26302
> CREATE TABLE model (
name varchar(3),
desc varchar(25)
)
The specified data type is not valid. [ Data type (if known) = varchar ]

      

+2


source to share


4 answers


Because it's the DESC

SQL keyword. You can use a different column name (for example description

), or put parentheses around DESC

:



[desc] VARCHAR(25)

      

+6


source


SqlCe is a Unicode-only database, so you need nvarchar instead of varchar.



+6


source


DESC

is a reserved SQL keyword. In SQL Server, you can escape the reserved name by surrounding the name with [], for example [desc]

.

Or, don't use an abbreviation or name your column Description

.

+1


source


Both repsons I've seen are correct.

DESC is short for DESCENDING (as in the ORDER BY clause) and is therefore reserved. Using "desc" or [desc] will avoid this problem and allow field names with spaces, etc., as well.

(Note: I don't recommend using keywords as field names or aliases. I also don't recommend putting spaces in them, but with 'or [] you can ...)

0


source