[英]Relationship between Identity tables and Other tables in ASP.NET MVC 5
在ASP.NET MVC 5項目中,首先通過代碼創建數據庫和標識表,然后在該數據庫中通過SQL創建其他表(而不是首先通過代碼),並且我想通過用戶ID將用戶表與某些表連接起來。
說一個名為Qwerty的數據庫,身份表是:
dbo.Users
dbo.Roles
dbo.UserClaims
... ect
我想像這樣通過SQL創建表:
Create Table Topic.Topic
(
TopicID int Primary key identity(1,1) not null,
TopicAddress nvarchar(255) not null
)
Create Table dbo.Bookmark
(
BookmarkID int Primary key identity(1,1) not null,
BookmarkDate datetime default getdate() not null,
UserID int constraint FK_Favorites_Users_UserID foreign key (UserID) references Users(UserID) not null
)
主題表創建成功,但是當我為書簽表運行SQL代碼時,它給我錯誤並用紅線標記“ 用戶 (表名)”一詞
默認情況下,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
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.