0

I have database with a table called members, which stores data for my admin,client,technicians all in one.But now I want to break this table into three separate tables as members and techs.members table has the common fields for both all admin,client and technician. Technicians have more data than the other two.These extra data I want to store in another table called techs.In members table I have a field as ID and in techs table there is a field as tech ID.What I want is when I insert a technician data for members table that particular ID should get inserted to techs table tech ID column

4
  • 1
    What RDBMS are you using (MySql, SQL Server, Oracle, ...)? And how is ID column defined in members table? Is it identity (auto_increment) column? Commented Jul 30, 2013 at 4:21
  • post sample code you are using to insert technician data Commented Jul 30, 2013 at 4:25
  • can you provide your member table field and other table field,so we can easily create your query. Commented Jul 30, 2013 at 4:50
  • I am using MySql.My members table fields are Id,Name,Username,Password,Level,Address,Phone.techs table fields are techID,price,company,comments,Rate,qualifications.Id in members table is primary key not null auto_increment Commented Jul 30, 2013 at 5:42

1 Answer 1

3

For mysql (with auto_increment id in members table) it can be:

START TRANSACTION;
insert into members ...
insert into admin ... (id, ...) values (last_insert_id(), ...);
COMMIT;

UPDATE
After you provided structure an example is:

    START TRANSACTION;
    insert into members (Name, Username, Password, Level, Address, Phone)
       values ('name','username','password','level','address','12345')
    insert into techs (techID, price, company, comments, rate, qualification)
       values (last_insert_id(), 10, 'company', 'comment', 1, 'qualification');
    COMMIT;

Members.id will be created automatically because it's auto_increment field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.