CREATE DATABASE Company;
USE Company;
CREATE TABLE Customer( id VARCHAR(6) NOT NULL, name VARCHAR(30), address VARCHAR(30), salary DECIMAL(10,2), CONSTRAINT PRIMARY KEY (id)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE Orders( id VARCHAR(6) NOT NULL, date DATE, customerId VARCHAR(6) NOT NULL, CONSTRAINT PRIMARY KEY (id), CONSTRAINT FOREIGN KEY(customerId) REFERENCES Customer(id)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE Item( code VARCHAR(6) NOT NULL, description VARCHAR(50), unitPrice DECIMAL(8,2), qtyOnHand INT(5), CONSTRAINT PRIMARY KEY (code)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE OrderDetail( orderId VARCHAR(6) NOT NULL, itemCode VARCHAR(6) NOT NULL, qty INT(11), unitPrice DECIMAL(8,2), CONSTRAINT PRIMARY KEY (orderId,itemCode), CONSTRAINT FOREIGN KEY (orderId) REFERENCES Orders(id), CONSTRAINT FOREIGN KEY (itemCode) REFERENCES Item(code)
)ENGINE=InnoDB DEFAULT CHARSET=latin1;
/////////////////////////////////////////////////////////////////////////
INSERT INTO Customer VALUES( 'C001 ', 'Danapala ', 'Panadura ',54000);
INSERT INTO Customer VALUES( 'C002 ', 'Gunapala ', 'Matara ',44000);
INSERT INTO Customer VALUES( 'C003 ', 'Somapala ', 'Galle ',82000);
INSERT INTO Customer VALUES( 'C004 ', 'Siripala ', 'Galle ',24000);
INSERT INTO Customer VALUES( 'C005 ', 'Jinadasa ', 'Panadura ',94000);
INSERT INTO Customer VALUES( 'C006 ', 'Sepalika ', 'Kalutara ',58000);
INSERT INTO Customer VALUES( 'C007 ', 'Jinasena ', 'Ambalangoda ',51000);
INSERT INTO Customer VALUES( 'C008 ', 'Somadasa ', 'Baddegama ',34000);
INSERT INTO Customer VALUES( 'C009 ', 'Danasiri ', 'Moratuwa ',29000);
INSERT INTO Customer VALUES( 'C010 ', 'Somasiri ', 'Kandy ',64000);
///////////////////////////////////////////////////////////////////////
INSERT INTO Item VALUES( 'P001 ', 'Keerisamba
References: ///////////////////////////////////////////////////////////////////////// INSERT INTO Customer VALUES( 'C001 ', 'Danapala ', 'Panadura ',54000); INSERT INTO Customer VALUES( 'C002 ', 'Gunapala ', 'Matara ',44000); INSERT INTO Customer VALUES( 'C003 ', 'Somapala ', 'Galle ',82000); INSERT INTO Customer VALUES( 'C004 ', 'Siripala ', 'Galle ',24000); INSERT INTO Customer VALUES( 'C005 ', 'Jinadasa ', 'Panadura ',94000); INSERT INTO Customer VALUES( 'C006 ', 'Sepalika ', 'Kalutara ',58000); INSERT INTO Customer VALUES( 'C007 ', 'Jinasena ', 'Ambalangoda ',51000); INSERT INTO Customer VALUES( 'C008 ', 'Somadasa ', 'Baddegama ',34000); INSERT INTO Customer VALUES( 'C009 ', 'Danasiri ', 'Moratuwa ',29000); INSERT INTO Customer VALUES( 'C010 ', 'Somasiri ', 'Kandy ',64000); /////////////////////////////////////////////////////////////////////// INSERT INTO Item VALUES( 'P001 ', 'Keerisamba Retail ',105.00,3000); INSERT INTO Item VALUES( 'P002 ', 'Keerisamba 5Kg ',525.00,200); INSERT INTO Item VALUES( 'P005 ', 'Red Raw Rice ',60.00,6000); INSERT INTO Item VALUES( 'P006 ', 'Red Raw Rice 10Kg Pack ',560.00,300); =============== INSERT INTO Customer VALUES( 'C001 ', 'Danapala ', 'Panadura ',54000); String sql="Insert into Customer values( 'C001 ', 'Danapala ', 'Matara ',50000)"; String sql="Insert into Customer values( 'C001 ', 'Danapala ', 'Matara ',50000)"; stm.executeUpdate(sql);