Embarrassing Problem with inserting record...!

Hi
How can I insert record R1 to Person Table
Record: R1
ID: 28
Person_Id: 28
Name: Sara
Family: Iranmanesh
Table: Person
ID: Autonumber
Person_Id: number
Name: Char[30]
Family: Char[40]
Note: This table belongs to an mdb file.
Regards,
Elham


Answer this question

Embarrassing Problem with inserting record...!

  • rs12345

    I sense some redundancy in your schema. What’s the difference between ID and Person_Id



  • philip.engstrom

    You'd use the INSERT SQL statement. You probably have a problem with the ID field. You can't set it, it is automatically assigned by the Jet driver since the field type is "Autonumber". Just omit it from the INSERT statement.


  • omron

    It looks like R1.ID and R1.Person_ID are the same

    DECLARE @PersonID int

    DECLARE @Name Char(30)

    DECLARE @Family Char(40)

    SET @PersonID = (SELECT Person_ID from Table1 WHERE ID = 28),

    @Name = (SELECT Name from Table1 WHERE ID = 28),

    @Family = (SELECT Family from Table1 WHERE ID = 28)

    INSERT INTO Person(Person_ID, Name, Family) VALUES(@PersonID, @Name, @Family)

    ...or if it's more than one record, you'll need a cursor

    ...and if it's a regular task, you might want to write a stored procedure.

    If so, respond and I'll post the code.

    Adamus



  • Schayin

    I cannot insert that record because there is a recursive relationship in my table. So I have to insert that record without Person_Id. I mean I must leave it with null value. And then try to update that record and set the Person_Id to its value. These processes might be occurred in a procedure. If I wanna insert that record with null value in Person_Id you must change some options in your database. Checking this article will get there:

    http://www.kbalertz.com/kb_Q208391.aspx

    I got it now then decide to share with the others in this forum.

    Regards


  • Embarrassing Problem with inserting record...!