|
Posted by Alwik on 09/22/05 00:16
> I am new to SQL administration.
>
> >From a list of IDs that are the primary key in one table (i.e. Customer
> Table), I want to make changes in tables that use those IDs as a
> foreign key.
>
> Basically I want to say:
>
> If fk_ID is in list [1,2,3,4,5] then
> do these statements to that record
> End if
>
> Where do I begin?
>
> Thanks for help with this low-level view of SQL programming.
>
Let's try a simple example
Customers table has a field cust_id, orders table has field ord_freight and
ord_custId which is FK.
When you want to update ord_freight for known customer ids you can execute:
UPDATE orders SET ord_freight = 15 WHERE ord_custId IN (1,2,3,4,5)
but let's assume that you know only names of cusomers - then you can use
joins and filter orders using using names and relations between tables.
I think that the best place to start reading are MS SQL Server books
online - look for topic: update (described) - there are some examples etc.
You can use cursors as well and process records on a one by one basis, but I
think that update will solve many of your problems.
I hope this helps
Tomik
Navigation:
[Reply to this message]
|