Re: Syntax to add records if primary key = list



> 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


.



Relevant Pages

  • Re: Syntax to add records if primary key = list
    ... >>From a list of IDs that are the primary key in one table (i.e. Customer ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (comp.databases.ms-sqlserver)
  • Syntax to add records if primary key = list
    ... I am new to SQL administration. ... >>From a list of IDs that are the primary key in one table (i.e. Customer ...
    (comp.databases.ms-sqlserver)
  • RE: Just a little tease on how to place proper product spin.
    ... IDS may be ... horrendous of product positioning.> ... Product overlap also gives a customer choice. ... on with IBM. ...
    (comp.databases.informix)
  • Re: OOP - a question about database access
    ... >>and project so much better in SQL DBMSes than in ODBMSes, ... >>100x more bytes from the database, just because you want your objects to ... > a related invoice.. ... > assoication from the customer to the invoice collection and have done ...
    (comp.object)
  • Re: object databases
    ... Now, tell me, you can do all that with 2 lines of code with SQL ... didn't provide the Customer, Order and OrderDetail classes. ... If you try to map classes to tables, ...
    (comp.object)