Professional Web Applications Themes

Inserting data into tables with relations - Microsoft SQL / MS SQL Server

This is actually kind of continuation to my previous question but I thought that I'd start a new topic anyway. I have two tables tableA and tableB. tableA: tableB: - eka(int) - toka(int) - name(varchar) - eka(int) - id(int) - ope(varchar) - updated(datetime) The tableA is a parent table and eka is the primary key. tableB's eka is foreign key. I need to insert data to tableA and into tableB. The idea is that if some table has relations to some other table then it would fill the relation table first and then the parent table. Is that possible ? ...

  1. #1

    Default Inserting data into tables with relations

    This is actually kind of continuation to my previous question
    but I thought that I'd start a new topic anyway.

    I have two tables tableA and tableB.
    tableA: tableB:
    - eka(int) - toka(int)
    - name(varchar) - eka(int)
    - id(int) - ope(varchar)
    - updated(datetime)

    The tableA is a parent table and eka is the primary key.
    tableB's eka is foreign key.

    I need to insert data to tableA and into tableB.
    The idea is that if some table has relations to some other
    table then it would fill the relation table first and then
    the parent table. Is that possible ? It could fill the parent
    table first also if it doesn't work the other way.

    I have a C++ program that constructs the sql string.
    That I don't need help with, but this actual sql query I could
    use some help with.

    ----
    mkarja
    mkarja Guest

  2. #2

    Default Re: Inserting data into tables with relations

    Thanks for the answer.
    Would it be possible somehow to recognise if the table has relations
    to some other table then it would populate the foreign key table as well.
    If there isn't any relations then of course it would only insert the data
    into the one table only.
    Or would I have to do this programmatically with C++ ?

    ----
    mkarja


    "David Portas" <org> wrote in message news:<ex5G#phx.gbl>... 
    >
    > You must populate the parent table first otherwise the insert into TableB
    > will fail (assuming the FK value doesn't already exist in TableA).
    >

    >
    > The syntax is:
    >
    > INSERT INTO tableA (eka, [name], id) VALUES (...)
    > INSERT INTO tableB (toka, eka, ope, updated) VALUES (...)[/ref]
    mkarja Guest

  3. #3

    Default Re: Inserting data into tables with relations

    Does anyone have any idea if this could be done with sql somehow ?
    I'm starting to think how to do it in the program, but if it could
    be done with sql more easily I would apreciate very much if someone
    could tell me how to do it or at least point me in the right direction.

    ----
    mkarja


    com (mkarja) wrote in message news:<google.com>... 
    > >
    > > You must populate the parent table first otherwise the insert into TableB
    > > will fail (assuming the FK value doesn't already exist in TableA).
    > >
    > > 
    > >
    > > The syntax is:
    > >
    > > INSERT INTO tableA (eka, [name], id) VALUES (...)
    > > INSERT INTO tableB (toka, eka, ope, updated) VALUES (...)[/ref][/ref]
    mkarja Guest

Similar Threads

  1. Inserting data into two seperate tables with Dreamweaver
    By lutzlut896 in forum Macromedia Dynamic HTML
    Replies: 1
    Last Post: October 13th, 07:40 PM
  2. inserting records to multiple tables in sql
    By YasDotnet in forum Dreamweaver AppDev
    Replies: 2
    Last Post: July 30th, 02:19 PM
  3. Selecting tables with relations
    By mkarja in forum Microsoft SQL / MS SQL Server
    Replies: 2
    Last Post: August 6th, 12:46 PM
  4. Replies: 1
    Last Post: July 10th, 08:29 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139