Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Posts
    7

    Unanswered: Insert values into 2 tables with one INSERT

    Is this the appropriate way to insert information into a database with 2 tables (related with empID fields)

    INSERT INTO table1
    empID, first, last, dept, district
    INSERT INTO table 2
    className, classType, classDate

    I am using ColdFusion to send the information to the database.

    Thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322

    Re: Insert values into 2 tables with one INSERT

    Originally posted by helios76
    Is this the appropriate way to insert information into a database with 2 tables (related with empID fields)

    INSERT INTO table1
    empID, first, last, dept, district
    INSERT INTO table 2
    className, classType, classDate

    I am using ColdFusion to send the information to the database.

    Thanks!

    uhhhh...no

    post the ddl for your tables...syntax is

    INSERT INTO myTable (col1, col2, ect)
    SELECT col1, col2, ect
    FROM SomeOtherTable
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Oct 2003
    Posts
    7
    OK, full story of what I am trying to do.
    Create a form that will go through ColdFusion to the database. This is how CFMX uses the SQL commands:

    <cfquery name="AddEmployee" datasource="CompanyInfo">
    INSERT INTO Employee
    (Emp_ID,FirstName,LastName, Dept_ID,Contract)
    VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
    </cfquery>

    The #Form.Emp_ID# is how CFMX knows what was entered on the HTML form and then sends it to the database.

    What my goal is, is to send data to 2 tables that are linked by Emp_ID in the same database.

  4. #4
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Originally posted by helios76
    OK, full story of what I am trying to do.
    Create a form that will go through ColdFusion to the database. This is how CFMX uses the SQL commands:

    <cfquery name="AddEmployee" datasource="CompanyInfo">
    INSERT INTO Employee
    (Emp_ID,FirstName,LastName, Dept_ID,Contract)
    VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
    </cfquery>

    The #Form.Emp_ID# is how CFMX knows what was entered on the HTML form and then sends it to the database.

    What my goal is, is to send data to 2 tables that are linked by Emp_ID in the same database.
    You could add another insert in batch like this:

    <cfquery name="AddEmployee" datasource="CompanyInfo">
    INSERT INTO Employee
    (Emp_ID,FirstName,LastName, Dept_ID,Contract)
    VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
    INSERT INTO Employee2
    (Emp_ID,FirstName,LastName, Dept_ID,Contract)
    VALUES (#Form.Emp_ID#,'#Form.FirstName#','#Form.LastName# ', #Form.Dept_ID#,'#Form.Contract#')
    </cfquery>

Posting Permissions

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