-- creating CustomersTable CREATE TABLE CustomersTable ( cID INTEGER PRIMARY KEY, firstName TEXT NOT NULL, lastName TEXT NOT NULL, dob TEXT NOT NULL, streetAddress TEXT NOT NULL, city TEXT NOT NULL, par_state TEXT NOT NULL, country TEXT NOT NULL, emailAddress TEXT NOT NULL, phoneNo TEXT NOT NULL ); -- table population INSERT INTO CustomersTable VALUES (1, 'Imani', 'Adonis', '19/10/2002', '17 Research Crescent', 'Mandeville', 'Manchester', 'Jamaica', '[email protected]', '876-513-0297'); INSERT INTO CustomersTable VALUES (2, 'Sanique', 'Johnson', '19/1/2002', '15 Steer Town', "St. Ann's Bay", 'St. Ann', 'Jamaica', '[email protected]', '876-988-0756'); INSERT INTO CustomersTable VALUES (3, 'DeJuan', 'Williams', '15/4/2003', '2 Cascade Drive', 'Cascade', 'St. Ann', 'Jamaica', '[email protected]', '876-345-2143'); INSERT INTO CustomersTable VALUES (4, 'Shawn', 'Douglas', '6/3/2000', '4 Apple Lane', 'Albion', 'New York', 'United States', '[email protected]', '585-765-9876'); INSERT INTO CustomersTable VALUES (5, 'Karen', 'White', '10/9/1987', '38 Miller Oaks Circle', 'Atlanta', 'Georgia', 'United States', '[email protected]', '404-927-9765'); INSERT INTO CustomersTable VALUES (6, 'Maria', 'Trogdon', '21/8/1964', '1172 Wildrose Lane', 'Detroit', 'Michigan', 'United States', '[email protected]', '313-840-8060'); INSERT INTO CustomersTable VALUES (7, 'James', 'Brodeur', '24/2/1962', '65 Osborne Road', 'Kingsclere', 'Reading', 'United Kingdom', '[email protected]', '+44 078-6312-1650'); INSERT INTO CustomersTable VALUES (8, 'Eduardo', 'Franklin', '18/2/1968', '4277 Reserve Street', 'Yarker', 'Ontario', 'Canada', '[email protected]', '613-377-7648'); INSERT INTO CustomersTable VALUES (9, 'Ruby', 'Martin', '15/1/1952', '17 Miles Drive', 'Lucea', 'Hanover', 'Jamaica', '[email protected]', '876-657-2133'); INSERT INTO CustomersTable VALUES (10, 'Carroll', 'Lawrence', '16/5/1985', '9 Norbrook Way', 'Kingston', 'Kingston', 'Jamaica', '[email protected]', '876-826-6231'); INSERT INTO CustomersTable VALUES (11, 'Jayme', 'Ramsey', '29/11/2001', '32 Bonitto Avenue', 'Spanish Town', 'St. Catherine', 'Jamaica', '[email protected]', '876-502-7471'); INSERT INTO CustomersTable VALUES (12, 'Erin', 'Christopher', '20/10/1991', '4059 Pleasant Hill Road', 'Miami', 'Florida', 'United States', '[email protected]', '561-948-8765'); INSERT INTO CustomersTable VALUES (13, 'Eugene', 'Cooper', '25/3/1975', '47 Carolina Avenue', 'Greenside', 'Trelawny', 'Jamaica', '[email protected]', '876-970-2144'); INSERT INTO CustomersTable VALUES (14, 'David', 'Anderson', '1/4/2000', '10 Woodland Heights', 'Ocho Rios', 'St. Mary', 'Jamaica', '[email protected]', '876-969-2579'); INSERT INTO CustomersTable VALUES (15, 'Stephen', 'Shields', '1/12/1974', '34 Alpha Avenue', 'Longview', 'Texas', 'United States', '[email protected]', '903-987-5096'); -- creating Account Information Table CREATE TABLE AccountInfo ( accNo INTEGER PRIMARY KEY, accType1 TEXT NOT NULL, accType2 TEXT NOT NULL, cID INTEGER NOT NULL, accStatus TEXT NOT NULL, accActivationDate TEXT NOT NULL, branchCode INTEGER NOT NULL, totalBalance FLOAT NOT NULL ); -- table population INSERT INTO AccountInfo VALUES (0801002, 'Savings', 'Regular Save', 1, 'Active', '19/10/2020', 00008, 4000.00); INSERT INTO AccountInfo VALUES (0902002, 'Savings', 'Regular Save', 2, 'Active', '8/2/2021', 00009, 9460.00); INSERT INTO AccountInfo VALUES (0903001, 'Savings', 'Quick Save', 3, 'Active', '6/8/2021', 00009, 4090.00); INSERT INTO AccountInfo VALUES (1204008, 'Chequing', 'Current Account', 4, 'Active', '5/11/2019', 00012, 10000.00); INSERT INTO AccountInfo VALUES (1005011, 'Chequing', 'Business Current Account - Sole Trader', 5, 'Inactive', '7/7/1997', 00001, 24500.00); INSERT INTO AccountInfo VALUES (1206004, 'Savings', 'S.T.A.R.T', 6, 'Active', '6/2/1989', 00012, 300895.00); INSERT INTO AccountInfo VALUES (1207012, 'Savings', 'Foreign Currency Account', 7, 'Active', '4/10/1986', 00012, 900560.00); INSERT INTO AccountInfo VALUES (1408003, 'Savings', 'Max Deposit', 8, 'Inactive', '3/5/1973', 00014, 20070.00); INSERT INTO AccountInfo VALUES (0209005, 'Savings', 'Gold Club', 9, 'Active', '4/12/1968', 00002, 7609800.00); INSERT INTO AccountInfo VALUES (0200904, 'Savings', 'S.T.A.R.T', 9, 'Active', '3/6/2003', 00009, 87283.00); INSERT INTO AccountInfo VALUES (1201006, 'Savings', 'Sunshine Savers', 10, 'Suspended', '5/9/2021', 00012, 11000.00); INSERT INTO AccountInfo VALUES (1001002, 'Savings', 'Regular Save', 10, 'Active', '5/9/2015', 00010, 843586.00); INSERT INTO AccountInfo VALUES (1001102, 'Chequing', 'Regular Save', 11, 'Active', '1/2/2022', 00010, 5000.00); INSERT INTO AccountInfo VALUES (1201201, 'Savings', 'Quick Save', 12, 'Active', '6/3/2011', 00008, 20560.00); INSERT INTO AccountInfo VALUES (0501307, 'Savings', 'Special Occasions Savings Plan', 13, 'Suspended', '7/4/2005', 00005, 1300.00); INSERT INTO AccountInfo VALUES (1101409, 'Chequing', 'Business Current Account - Company', 14, 'Active', '2/9/2019', 00011, 19100.00); INSERT INTO AccountInfo VALUES (0801402, 'Savings', 'Regular Save', 14, 'Inactive', '9/8/2021', 00008, 49872.00); INSERT INTO AccountInfo VALUES (0401512, 'Savings', 'Foreign Currency Account', 15, 'Active', '6/1/2007', 00004, 653450.00); -- creating Transaction Information Table CREATE TABLE TransactionInfo ( transactionID INTEGER PRIMARY KEY, accNo INTEGER NOT NULL, transactionType TEXT NOT NULL, amount FLOAT NOT NULL ); -- table population INSERT INTO TransactionInfo VALUES (1, 0903001, 'Deposit', 540.00); INSERT INTO TransactionInfo VALUES (2, 1206004, 'Deposit', 1000.00); INSERT INTO TransactionInfo VALUES (3, 1001102, 'Transfer', 5600.00); INSERT INTO TransactionInfo VALUES (4, 0801002, 'Withdrawal', 600.00); INSERT INTO TransactionInfo VALUES (5, 0801402, 'Deposit', 1750.00); INSERT INTO TransactionInfo VALUES (6, 0902002, 'Withdrawal', 2000.00); INSERT INTO TransactionInfo VALUES (7, 0801002, 'Deposit', 3050.00); INSERT INTO TransactionInfo VALUES (8, 1101409, 'Transfer', 20500.00); INSERT INTO TransactionInfo VALUES (9, 1207012, 'Deposit', 10000.00); INSERT INTO TransactionInfo VALUES (10, 0401512, 'Withdrawal', 250000.00); INSERT INTO TransactionInfo VALUES (11, 1204008, 'Withdrawal', 1000.00); INSERT INTO TransactionInfo VALUES (12, 1101409, 'Deposit', 10000.00); INSERT INTO TransactionInfo VALUES (13, 1001002, 'Withdrawal', 50000.00); INSERT INTO TransactionInfo VALUES (14, 1001102, 'Withdrawal', 1500.00); INSERT INTO TransactionInfo VALUES (15, 0902002, 'Deposit', 4500.00); -- creating Branch Information Table CREATE TABLE Branches ( branchCode INTEGER PRIMARY KEY, branchName TEXT NOT NULL ); -- table population INSERT INTO Branches VALUES (00001, 'Operations Centre'); INSERT INTO Branches VALUES (00002, 'Lucea'); INSERT INTO Branches VALUES (00003, 'Black River'); INSERT INTO Branches VALUES (00004, 'Montego Bay'); INSERT INTO Branches VALUES (00005, 'Falmouth'); INSERT INTO Branches VALUES (00006, 'Savanna-la-Mar'); INSERT INTO Branches VALUES (00007, 'May Pen'); INSERT INTO Branches VALUES (00008, 'Mandeville'); INSERT INTO Branches VALUES (00009, "St. Ann's Bay"); INSERT INTO Branches VALUES (00010, 'Spanish Town'); INSERT INTO Branches VALUES (00011, 'Port Maria'); INSERT INTO Branches VALUES (00012, 'Kingston'); INSERT INTO Branches VALUES (00013, 'Port Antonio'); INSERT INTO Branches VALUES (00014, 'Half Way Tree'); INSERT INTO Branches VALUES (00015, 'Morant Bay'); SELECT CustomersTable.cID, CustomersTable.firstName, CustomersTable.lastName, AccountInfo.accNo, AccountInfo.accType1, AccountInfo.accType2, AccountInfo.accStatus FROM CustomersTable FULL JOIN AccountInfo ON CustomersTable.cID = AccountInfo.cID ORDER BY CustomersTable.lastName;
Write, Run & Share MySQL queries online using OneCompiler's MySQL online editor and compiler for free. It's one of the robust, feature-rich online editor and compiler for MySQL. Getting started with the OneCompiler's MySQL editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'MySQL' and start writing queries to learn and test online without worrying about tedious process of installation.
MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
....);
CREATE TABLE EMPLOYEE (
empId INTEGER PRIMARY KEY,
name TEXT NOT NULL,
dept TEXT NOT NULL
);
ALTER TABLE Table_name ADD column_name datatype;
INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');
TRUNCATE table table_name;
DROP TABLE table_name;
RENAME TABLE table_name1 to new_table_name1;
--Line1;
/* Line1,
Line2 */
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);
Note: Column names are optional.
INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');
SELECT column1, column2, ...
FROM table_name
[where condition];
SELECT * FROM EMPLOYEE where dept ='sales';
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001';
DELETE FROM table_name where condition;
DELETE from EMPLOYEE where empId='0001';
CREATE INDEX index_name on table_name(column_name);
CREATE UNIQUE INDEX index_name on table_name(column_name);
DROP INDEX index_name ON table_name;
Creating a View:
CREATE VIEW View_name AS
Query;
SELECT * FROM View_name;
ALTER View View_name AS
Query;
DROP VIEW View_name;
CREATE TRIGGER trigger_name trigger_time trigger_event
ON tbl_name FOR EACH ROW [trigger_order] trigger_body
/* where
trigger_time: { BEFORE | AFTER }
trigger_event: { INSERT | UPDATE | DELETE }
trigger_order: { FOLLOWS | PRECEDES } */
DROP TRIGGER [IF EXISTS] trigger_name;
CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;
CALL sp_name;
DROP PROCEDURE sp_name;
SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;
SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;
SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;
SELECT select_list from TABLE1 CROSS JOIN TABLE2;