SQL Server: composite PK issue when columns having different data type [closed]

我是研究僧i 提交于 2019-12-14 03:21:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!