You are here: Re: Database table data modifications with PK/FK relationship « MsSQL Server « IT news, forums, messages
Re: Database table data modifications with PK/FK relationship

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация