|
Posted by David Portas on 03/21/07 22:52
On 21 Mar, 21:48, ebade2...@gmail.com wrote:
> I have two tables (T1 and T2). In T1 I have a field FT1 that is a
> primary key in T2 I have a field FT2 that is a foreign key linked to
> FT1. These fields have been populated with data. Lets say that in one
> row of data I have in T1 under FT1 "my cell" as the data entry,
> similarly with T2 under FT2 I have 2 rows of data that also have "my
> cell" as the data entry. What is the best line of action is I wanted
> to change "my cell" to "my data"?
-- Method 1.
INSERT INTO T1 (FT1) VALUES ('MY DATA');
UPDATE T2 SET FT2 = 'MY DATA' WHERE FT2 = 'MY CELL';
DELETE FROM T1 WHERE FT1 = 'MY CELL';
-- Method 2.
ALTER TABLE T2 ADD CONSTRAINT fk_t2_t1
FOREIGN KEY (ft2) REFERENCES T1 (FT1) ON UPDATE CASCADE;
UPDATE T1 SET FT1 = 'MY DATA' WHERE FT1 = 'MY CELL';
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
Navigation:
[Reply to this message]
|