Results 1 to 8 of 8

Thread: MySQL Multi-User / Table Locking

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    207

    MySQL Multi-User / Table Locking

    Hi guys, Im using MySQL 5.0.

    Here is my two tables.

    Code:
    CREATE TABLE IF NOT EXISTS Invoice
    (
    InvoiceID	             MEDIUMINT	NOT NULL	AUTO_INCREMENT,
    InvoiceDate	DATE		NOT NULL,
    ClientID	             VARCHAR(7)	NOT NULL,
    Total		INTEGER(10,2)	NOT NULL,
    AmountPaid	INTEGER(10,2)	NOT NULL,
    PRIMARY KEY	(InvoiceID),
    FOREIGN KEY	(ClientID)	             REFERENCES	Clients(ClientID)
    );
    
    CREATE TABLE IF NOT EXISTS Transaction
    (
    InvoiceID	             MEDIUMINT	NOT NULL,
    ProductID	VARCHAR(7)	NOT NULL,
    QTY		INTEGER(2)	NOT NULL,
    FOREIGN KEY	(InvoiceID) 	REFERENCES	Invoice(InvoiceID),
    FOREIGN KEY	(ProductID)	REFERENCES	Products(ProductID)
    );
    The purpose of this is to record 1 InvoiceID to refer to multipul transaction items. So heres the problem. What if 2 transactions occured, then the below code will not work.

    Code:
    INSERT INTO Invoice (InvoiceDate, ClientID, Total, AmountPaid)
    VALUES (NOW(), 'OZT0001', 130.00, 50.00);
    
    INSERT INTO Transaction (InvoiceID, ClientID, ProductID, QTY, Total)
    VALUES (LAST_INSERT_ID(), 'RAM0001', 2);
    Is there a better way to construct this or any advise on how to go about this?
    Last edited by TURKINATOR; Oct 3rd, 2007 at 03:50 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width