Createtabletest1 (idintprimarykeynotnull, valueint) inserttest1select1, 2go -- From the createtabletest2 table (partition (id), valueint) go -- Step 1: Find the foreign key constraint name in Table test2 -- constraint -- yes
Create table test1 (id int primary key not null, value int) insert test1 select 1, 2 go -- create table test2 (id int references test1 (id), value int) go -- Step 1: Find the foreign key constraint name in Table test2 -- 2000 exec sp_helpconstraint 'test2' -- yes
Create table test1 (id int primary key not null, value int)
Insert test1 select 1, 2
Go
-- Slave table
Create table test2 (id int references test1 (id), value int)
Go
-- Step 1: Find the foreign key constraint name in Table test2
-- 2000
Exec sp_helpconstraint 'test2'
-- The foreign key constraint name can be found in the constraint_name attribute.
-- 2005
Select name
From sys. foreign_key_columns f join sys. objects o on f. constraint_object_id = o. object_id
Where f. parent_object_id = object_id ('test2 ')
/*
Name
---------------------------------
FK _ test2 _ id _ 08EA5793 */
-- Step 2: delete the foreign key constraint
Alter table test2 drop constraint FK _ test2 _ id _ 08EA5793
-- Step 3: Check whether the table contains foreign key constraints.
-- You only need to use the search statement in step 1.