execute sql task
hi,
i have two tables.
like
EMP
emp id--primary key
Company
id-fORIEGN KEY WITH EMP ID COLUMN.
i want delete primary key on emp table and load data again create primary key.
but i am getting bellow error.
Error: The constraint 'PK_empid' is being referenced by table 'Company', foreign key constraint 'FK_company_id.
company
May 10th, 2011 2:23am
Disable the constraint for the duration of the load, and then re-enable afterwards. Write simple T-SQL, ALTER TABLE...
to do this, and run it at the start and end of your package so as to disable and enable the constriant(s) respectively
Please check the
Jamie's blog for loading the related tables.
Let us TRY this |
My Blog :: http://quest4gen.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 2:34am
First remove the relationship between two tables then delete primary key.
May 10th, 2011 2:35am
can we disable primarykey and foriegn key
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 2:36am
Yes you can disable .
May 10th, 2011 2:39am
Disable the constraint for the duration of the load, and then re-enable afterwards. Write simple T-SQL, ALTER TABLE...
to do this, and run it at the start and end of your package so as to disable and enable the constriant(s) respectively
Please check the
Jamie's blog for loading the related tables.
Let us TRY this |
My Blog :: http://quest4gen.blogspot.com/
This will leave orphaned records in the Company table and potentially still result in an error, especially if there are records in the
Company table that have no corresponding empid
in the EMP table.Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt)
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 2:40am
First remove the relationship between two tables then delete primary key.
This will leave orphaned records in the Company table and potentially still result in an error, especially if there are records in the
Company table that have no corresponding empid
in the EMP table.Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt)
May 10th, 2011 2:40am
He doesn't state that. He states that he wants to load the EMP table data again. There is no mention of reloading the
Company data again. If he is going to reload Company
data again, your suggestion will work. If he doesn't load the Company data again, your suggestion will fail
Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt)
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 2:48am
ALTER
INDEX PK_tblType
ON dbo.tblType
DISABLE
ALTER
INDEXPK_empid
on dbo.emp
rebuild
i was nun above two
querys. primary key was disabled but keys not enabled.
i was tryed with create primary
key, system shown isobject name is there in databse.
how can i enable
INDEX
PK_empid ON dbo.emp DISABLE
May 10th, 2011 2:59am
Hi Vamsi,
please check the Jamie's blog.. and use the following approach
"2) Disable the foreign key constraint prior to loading the two tables and then re-enable it again afterwards. Disabling can be done using the following DDL:
ALTER TABLE <table_name> NOCHECK CONSTRAINT <constraint_name>
You can re-enable again after executing the data-flow with the following DLL:
ALTER TABLE <table_name> WITH CHECK CHECK CONSTRAINT <constraint_name>"
Let me know your observation.Let us TRY this |
My Blog :: http://quest4gen.blogspot.com/
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 3:09am
Object 'PK_EMPID' cannot be disabled or enabled. This action applies only to foreign key and check constraints.
I GOT THIS ERROR
May 10th, 2011 4:06am
Object 'PK_EMPID' cannot be disabled or enabled. This action applies only to foreign key and check constraints.
I GOT THIS ERROR
You are trying to disable the primary key, not the foreign key.MCTS, MCITP - Please mark posts as answered where appropriate.
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 4:10am
yes. i am trying to disable primary key. i want disable primary key only
May 10th, 2011 4:13am
yes. i am trying to disable primary key. i want disable primary key only
Which command did you use?MCTS, MCITP - Please mark posts as answered where appropriate.
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 4:25am
It may pay you to have a read of
http://www.mssqlcity.com/Articles/General/using_constraints.htm to get a better understanding of the terms used by others replying to your problem.Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt)
May 10th, 2011 4:59am
First i was delete foriegn key and next delete the primary key
lload the data and re create foriegn key and primary key. plz let me know this process wes better or not.
Free Windows Admin Tool Kit Click here and download it now
May 10th, 2011 4:59am
You should create the Primary Key before you create the Foreign Key.
BTW, are you deleteing and reloading the Company data as well? if not, you may get an error when creating the Foreign Key as the
Company table may contain old emp id data. You will need to delete records in
Company that have an emp id not found in the
EMP table. This query will do the trick:
DELETE
FROM Company
WHERE NOT EXISTS (SELECT [emp id] FROM EMP WHERE EMP.[emp id] = Company.[emp id])
You will need to replace [emp id] with the actual name of this column in your tables.
Jeff Wharton MSysDev (C.Sturt), MDbDsgnMgt (C.Sturt)
May 10th, 2011 7:36pm


