使用工具:LINQPad4
1.准备数据表
Customer(顾客表)-- Id(自增主键)Name(顾客姓名)Phone(顾客联系方式)
CREATE TABLE [dbo].[Customer]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NULL, [Phone] [nvarchar](16) NULL, CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]
顾客表建库脚本
Order(订单表)-- Id(自增主键)OrderName(订单名称)Content(订单内容)CustomerId(顾客id)
CREATE TABLE [dbo].[Order]( [Id] [int] IDENTITY(1,1) NOT NULL, [OrderName] [nvarchar](50) NULL, [Content] [nvarchar](256) NULL, [CustomerId] [int] NOT NULL, CONSTRAINT [PK_Order] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[Order] WITH CHECK ADD CONSTRAINT [FK_CustomerOrder] FOREIGN KEY([CustomerId]) REFERENCES [dbo].[Customer] ([Id]) GO ALTER TABLE [dbo].[Order] CHECK CONSTRAINT [FK_CustomerOrder]
订单表建库脚本
as
sa
as
as
s
s
时间: 2024-10-12 21:58:23