locked
transferring data from one table to another RRS feed

  • Question

  •  

    i have got these tables

     

    first table emp

     

    empid   empname  city  country

     

     

    second table emp1

    empid  empname   language

     

     

    i need to transfer data from emp1  to emp table..the column city and country are mandatory in emp.

    i need a query to transfer values from emp1 to emp and set the city and country field to value 1

     

    Thursday, July 19, 2007 10:06 AM

Answers

  • I guess thoste tables don't a record with id = 1.

     

    If you need to have the FK relationship, you'll need to make sure that any values inserted into the city and country fields have a record in the foreign key table.

     

     

    Thursday, July 19, 2007 10:39 AM

All replies

  • How about.

     

    INSERT INTO emp (empid, empname, city, country)

    SELECT empid, empname, 1, 1

    FRMO emp1

     

    Does that work?

    Thursday, July 19, 2007 10:15 AM
  • no that doesnt work

     

    error

    INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK_CITY_COUNTRY'. The conflict occurred in database 'asd', table 'COUNTRY', column 'Id'.
    The statement has been terminated.

     

     

    there are two more columns

     

    city table

     

    id   city          country

     

     and country table

     

     

    id  countryid   countryname

     

     

     


     

    Thursday, July 19, 2007 10:25 AM
  • I guess thoste tables don't a record with id = 1.

     

    If you need to have the FK relationship, you'll need to make sure that any values inserted into the city and country fields have a record in the foreign key table.

     

     

    Thursday, July 19, 2007 10:39 AM
  • Please post the table DDL.
    Thursday, July 19, 2007 6:17 PM