问题
see my code it is not working but could not understand why?
i was trying to create composite pk having columns with different data type
when i tried this
CREATE TABLE [dbo].[ControllerActionItems](
[ControllerName] [varchar](50) NULL,
[ActionName] [varchar](50) NULL,
[RoleID] [int] NULL,
primary key ([ControllerName], [ActionName],[RoleID])
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
getting this error message
Msg 1709, Level 16, State 1, Line 2 Cannot use TEXTIMAGE_ON when a table has no text, ntext, image, varchar(max), nvarchar(max), non-FILESTREAM varbinary(max), xml or large CLR type columns.
solved updated code
CREATE TABLE [dbo].[ControllerActionItems](
[ControllerName] [varchar](50) NOT NULL,
[ActionName] [varchar](50) NOT NULL,
[RoleID] [int] NOT NULL,
primary key ([ControllerName], [ActionName],[RoleID])
)
回答1:
As the error states, you need one of the indicated columns to use TEXTIMAGE_ON, such as if you used varchar(MAX)
instead of varchar(50)
. However, according to this other answer what you're doing seems redundant anyways, as the default behavior is to store large-text-value columns in PRIMARY.
Unless you actually have a large-format column in the table, you should simply remove TEXTIMAGE_ON [PRIMARY]
from the SQL statement.
来源:https://stackoverflow.com/questions/44891816/sql-server-composite-pk-issue-when-columns-having-different-data-type