-- RIZALENE M. GERARDO -- create a table CREATE TABLE students ( NO int(30), id INTEGER(30), NAME VARCHAR (30), SEX VARCHAR (30), COURSE VARCHAR(30), YEAR VARCHAR (30), CPNumber VARCHAR(30), EMAIL VARCHAR(30)); INSERT INTO students VALUES (31, 19-10199, 'Malazzab, Jhon Khenette D.', 'M', 'BSIT', 3, '', ''); INSERT INTO students VALUES (32, 19-10684, 'Malazzab, Vincent Paul D.', 'M', 'BSIT',3, '', ''); INSERT INTO students VALUES (33, 19-10597, 'Medrano, Cherry B.', 'F', 'BSIT', 3, '09355600971', '[email protected]'); INSERT INTO students VALUES (34, 19-10582, 'Miravel, Jude Berg T.', 'M', 'BSIT', 3, '09265756222', ''); INSERT INTO students VALUES (35, 18-07479, 'Navarro, Mary Ann C.', 'F', 'BSIT',3, '', ''); INSERT INTO students VALUES (36, 19-10039, 'Nolasco, Rogine B.', 'F', 'BSIT', 3, '', ''); INSERT INTO students VALUES (37, 19-10655, 'Orpilla, Nino Jesus B.', 'M', 'BSIT', 3, '09654978186', ''); INSERT INTO students VALUES (38, 19-10071, 'Paypon, Myla D.', 'F', 'BSIT', 3, '09094695747', ''); INSERT INTO students VALUES (39, 18-071013, 'Pizarro, Ronamae D.', 'F', 'BSIT', 3, '09552643658', '[email protected]'); INSERT INTO students VALUES (40, 19-10843, 'Puerto, Karla Mae M.', 'F', 'BSIT', 3, '', ''); INSERT INTO students VALUES (41, 19-10001, 'Quillopo, Jessica Mae T.', 'F', 'BSIT', 3, '09355551268', ''); INSERT INTO students VALUES (42, 19-10475, 'Rabanal, Deborah M.', 'F', 'BSIT', 3, '09756992957', '[email protected]'); INSERT INTO students VALUES (43, 19-10494, 'Ragasa, Maureen A.', 'F', 'BSIT', 3, '', ''); INSERT INTO students VALUES (44, 15-10769, 'Ralleca, Jeremy D.', 'M', 'BSIT', 3, '', ''); INSERT INTO students VALUES (45, 19-10162, 'Repaje, Anngelyne B.', 'F', 'BSIT', 3, '097529286555', ''); INSERT INTO students VALUES (46, 19-10504, 'Rigon, Emerom S.', 'M', 'BSIT', 3, '09358831830', ''); INSERT INTO students VALUES (47, 19-10948, 'Salviejo, Lanie Rose F.', 'F', 'BSIT', 3, '09366173364', ''); INSERT INTO students VALUES (49, 19-10706, 'Serrano, Bernadette V.', 'F', 'BSIT', 3, '', ''); INSERT INTO students VALUES (50, 19-10174, 'Sotelo, Ma. Christine Joy R.', 'F', 'BSIT', 3, '09068412147', ''); INSERT INTO students VALUES (51, 19-11219, 'Sumauang, Rodolfo S.', 'M', 'BSIT', 3, '09773928642', ''); INSERT INTO students VALUES (52, 19-10517, 'Sus,Michael Jim D.', 'M', 'BSIT', 3, '', ''); INSERT INTO students VALUES (53, 18-07493, 'Taguba, Jhon Albert M.', 'M', 'BSIT', 3,'09750924068', ''); INSERT INTO students VALUES (54, 19-11417, 'Talamayan, John Charles T.', 'M', 'BSIT', 3, '', ''); INSERT INTO students VALUES (55, 19-22898, 'Talamayan, Kian Carl M.', 'M', 'BSIT', 3, '', ''); INSERT INTO students VALUES (56, 19-10982, 'Talosig, Princess Diane O.', 'F', 'BSIT', 3, '', ''); INSERT INTO students VALUES (57, 18-07087, 'Tan, Eloisa I.', 'F', 'BSIT', 3, '09653441034', '[email protected]'); INSERT INTO students VALUES (58, 19-10747, 'Temporal, Regine G.', 'F', 'BSIT', 3, '09951774978', ''); INSERT INTO students VALUES (59, 19-10779, 'Tierro, Gillian Mae I.', 'F', 'BSIT', 3, '09164978729',''); INSERT INTO students VALUES (60, 19-10243, 'Tierro, Noymie S.', 'F', 'BSIT', 3, '09363453289', ''); -- fetch some values SELECT * FROM students WHERE 1
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;