sql 主外键innsert 先插入主键表 delete 先删外键
--CREATE TABLE [Order Details] (
-- [OrderID] [int] NOT NULL ,
-- [ProductID] [int] NOT NULL ,
-- [UnitPrice] [money] NOT NULL CONSTRAINT [DF_Order_Details_UnitPrice] DEFAULT (0),
-- [Quantity] [smallint] NOT NULL CONSTRAINT [DF_Order_Details_Quantity] DEFAULT (1),
-- [Discount] [real] NOT NULL CONSTRAINT [DF_Order_Details_Discount] DEFAULT (0),
-- CONSTRAINT [PK_Order_Details] PRIMARY KEY CLUSTERED
-- (
-- [OrderID],
-- [ProductID]
-- ) ON [PRIMARY] ,
-- CONSTRAINT [FK_Order_Details_Orders] FOREIGN KEY
-- (
-- [OrderID]
-- ) REFERENCES [Orders] (
-- [OrderID]
-- ),
-- CONSTRAINT [FK_Order_Details_Products] FOREIGN KEY
-- (
-- [ProductID]
-- ) REFERENCES [Products] (
-- [ProductID]
-- ),
-- CONSTRAINT [CK_Discount] CHECK ([Discount] >= 0 and [Discount] <= 1),
-- CONSTRAINT [CK_Quantity] CHECK ([Quantity] > 0),
-- CONSTRAINT [CK_UnitPrice] CHECK ([UnitPrice] >= 0)
--) ON [PRIMARY]
--GO
--
--
--
--create table tabl3
--(
--tid int ,
--varchar1 varchar(20)
--)
--
--create table tablTT
--(
--TTid int ,
--TTvarchar1 varchar(20)
--)
--select * from tabl3
--
--
declare @i int ;
set @i=3;
while(@i<20)
begin
insert
into
tabl3(tid ,
varchar1
)values(@i,'ddd'+cast(@i as varchar(20)));
set @i=@i+1;
end
declare @i int ;
set @i=3;
while(@i<20)
begin
insert
into
tablTT(TTid ,
TTvarchar1
)values(@i,'FK'+cast(@i as varchar(20)));
set @i=@i+1;
end;