在ASP.NET MVC 5项目中,首先通过代码创建数据库和标识表,然后我在该数据库中通过SQL创建其他表(而不是首先通过代码),并且我想通过以下方式将User表与某些表连接起来:用户ID。
说一个名为Qwerty的数据库,身份表是:
"c:\path to file\filename without extension\c:\path to file contains invalid WIN32 path characters"
我想通过SQL创建表,如下所示:
dbo.Users
dbo.Roles
dbo.UserClaims
... ect
主题表已成功创建,但是当我为Bookmark表运行SQL代码时,它给我错误,并在 Users (表名)单词上标记为红色行
答案 0 :(得分:1)
默认情况下,Users的主键是nvarchar,因此,应使用该类型定义外键。
Create Table dbo.Bookmark
(
BookmarkID int Primary key identity(1,1) not null,
BookmarkDate datetime default getdate() not null,
UserID [nvarchar](128) constraint FK_Favorites_Users_UserID foreign key (UserID) references Users(UserID) not null
)