CREATE TABLE [dbo].[t_address]( [AddressId] [int] IDENTITY(1,1) NOT NULL, [AddressName] [nvarchar](500) NOT NULL, CONSTRAINT [PK_t_address] PRIMARY KEY CLUSTERED ( [AddressId] 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 CREATE TABLE [dbo].[t_customer]( [CustomerId] [int] IDENTITY(1,1) NOT NULL, [CustomerName] [nvarchar](50) NOT NULL, [LocationAddressId] [int] NULL, [PostalAddressId] [int] NULL, PRIMARY KEY CLUSTERED ( [CustomerId] 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 CREATE TABLE [dbo].[t_customer_info]( [CustomerId] [int] NOT NULL, [CustomerDescription] [nvarchar](50) NULL, CONSTRAINT [PK_t_customer_info] PRIMARY KEY CLUSTERED ( [CustomerId] 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 CREATE TABLE [dbo].[t_order]( [OrderId] [int] IDENTITY(1,1) NOT NULL, [CustomerId] [int] NOT NULL, [CreateDate] AS (getdate()), CONSTRAINT [PK__t_Order__C3905BCFC0AF501C] PRIMARY KEY CLUSTERED ( [OrderId] 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 CREATE TABLE [dbo].[t_order_product]( [OrderId] [int] NOT NULL, [ProductId] [int] NOT NULL, [Count] [int] NOT NULL, CONSTRAINT [PK_t_order_product] PRIMARY KEY CLUSTERED ( [OrderId] ASC, [ProductId] 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 CREATE TABLE [dbo].[t_product]( [ProductId] [int] IDENTITY(1,1) NOT NULL, [ProductName] [nvarchar](100) NOT NULL, [ProductPrice] [decimal](10, 2) NOT NULL, CONSTRAINT [PK_t_product] PRIMARY KEY CLUSTERED ( [ProductId] 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 CREATE TABLE [dbo].[t_test_person]( [TestId] [int] IDENTITY(1,1) NOT NULL, CONSTRAINT [PK_t_test_person] PRIMARY KEY CLUSTERED ( [TestId] 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].[t_customer] WITH CHECK ADD CONSTRAINT [FK_t_customer_t_address] FOREIGN KEY([LocationAddressId]) REFERENCES [dbo].[t_address] ([AddressId]) GO ALTER TABLE [dbo].[t_customer] CHECK CONSTRAINT [FK_t_customer_t_address] GO ALTER TABLE [dbo].[t_customer] WITH CHECK ADD CONSTRAINT [FK_t_customer_t_address1] FOREIGN KEY([PostalAddressId]) REFERENCES [dbo].[t_address] ([AddressId]) GO ALTER TABLE [dbo].[t_customer] CHECK CONSTRAINT [FK_t_customer_t_address1] GO ALTER TABLE [dbo].[t_customer_info] WITH CHECK ADD CONSTRAINT [FK_t_customer_info_t_customer] FOREIGN KEY([CustomerId]) REFERENCES [dbo].[t_customer] ([CustomerId]) GO ALTER TABLE [dbo].[t_customer_info] CHECK CONSTRAINT [FK_t_customer_info_t_customer] GO ALTER TABLE [dbo].[t_order] WITH CHECK ADD CONSTRAINT [FK_t_Order_To_t_Customer] FOREIGN KEY([CustomerId]) REFERENCES [dbo].[t_customer] ([CustomerId]) ON DELETE CASCADE GO ALTER TABLE [dbo].[t_order] CHECK CONSTRAINT [FK_t_Order_To_t_Customer] GO ALTER TABLE [dbo].[t_order_product] WITH CHECK ADD CONSTRAINT [FK_t_order_product_t_order] FOREIGN KEY([OrderId]) REFERENCES [dbo].[t_order] ([OrderId]) ON DELETE CASCADE GO ALTER TABLE [dbo].[t_order_product] CHECK CONSTRAINT [FK_t_order_product_t_order] GO ALTER TABLE [dbo].[t_order_product] WITH CHECK ADD CONSTRAINT [FK_t_order_product_t_product] FOREIGN KEY([ProductId]) REFERENCES [dbo].[t_product] ([ProductId]) ON DELETE CASCADE GO ALTER TABLE [dbo].[t_order_product] CHECK CONSTRAINT [FK_t_order_product_t_product] GO