我正在尝试找出创建 SQL Server 主键、外键和约束的最佳方法,以在 LINQ/实体数据对象中准确表示我的数据模型。让我们假设 - 为简化起见 - 我有四个主要表 - Cats、Dogs、Pets 和 Owners - 以及一个关联表:OwnersToPets:
create table Cats (
ID_Cats int NOT NULL IDENTITY PRIMARY KEY,
Name nvarchar(50) NOT NULL,
miceEaten int NULL
)
create table Dogs (
ID_Dogs int NOT NULL IDENTITY PRIMARY KEY,
Name nvarchar(50) NOT NULL,
favouriteToy nvarchar(50) NULL
)
create table Owners (
ID_Owners int NOT NULL IDENTITY PRIMARY KEY,
Name nvarchar(50) NOT NULL,
)
create table Pets (
ID_Pets int NOT NULL IDENTITY PRIMARY KEY, …Run Code Online (Sandbox Code Playgroud)