create table activity (acode integer,activityname varchar(25),stadium varchar(20),participantanum integer,prizemoney integer,schelduledate date); create table coach (pcode integer,name varchar(15),acode integer); describe activity; describe coach; select sign (-101); select power (4,-2); select mod(9,2); select round (45.9,-2); select round (-101.86,0); create table loans (id varchar(15),cus_name varchar(20),loan_amt integer,installment integer,int_rate decimal,startdate date,age integer); describe loans; insert into loans values('c1','sameer',300000,36,12.00,'2019-07-19',36); insert into loans values('c2','aryan',500000,60,10.00,'2018-03-22',65); insert into loans values('c4','ram',800000,48,null,'2018-03-08',48); insert into loans values('c6','prerna',300000,24,10.00,'2020-12-06',54); insert into loans values('c7','shikha',900000,36,12.50,'2020-01-03',42); insert into loans values('c8','radha',1000000,60,null,'2017-07-29',62); select * from loans; select cus_name,monthname(startdate)from loans where 60-age<=0; select cus_name,loan_amt from loans where monthname(startdate)='march'; select max(startdate)from loans; select length(' omicron varient '); select length(ltrim(' omicron varient ')); select length(rtrim(' omicron varient ')); select length(trim( 'omicron varient ')); select trim( 'omicron varient '); create table engg(id varchar(10),name varchar(15),age integer,city varchar(15),sub varchar(10),fee integer,mode varchar(10)); describe engg; insert into engg values('p1','sameer',20,'delhi','electr',45000,'offline'); insert into engg values('p2','aryan',21,'bhopal','comp',54000,'online'); insert into engg values('p4','ram',18,'chennai','comp',45000,'offline'); insert into engg values('p6','lata',20,'bhopal','mech',60000,'offline'); insert into engg values('p7','shikha',18,'indore','electr',34000,'online'); insert into engg values('p8','radha',19,'delhi','aero',23000,'online'); insert into engg values('p10','armaan',18,'bhopal','mech',34000,'offline'); select * from engg; select sum(fee),city from engg order by city desc; create table MobileMaster(M_id varchar(15),m_company varchar(15),m_name varchar(15),m_price integer,Qty integer,mfg_date date); describe MobileMaster; insert into MobileMaster values('mb001','samsung','galaxy',5400,13,'2013-2-12'); insert into MobileMaster values('mb003','nokia','n1100',1200,null,'2007-06-24'); insert into MobileMaster values('mb004','redmi','note7',13000,10,'2019-03-20'); insert into MobileMaster values('mb005','sony','xperiam',45000,6,'2017-11-10'); insert into MobileMaster values('mb006','oppo','selfieex',17000,7,'2010-08-01'); insert into MobileMaster values('mb007','redmi','note11',25000,15,'2021-11-21'); insert into MobileMaster values('mb008','oneplus','nord',30000,12,'2020-02-15'); insert into MobileMaster values('mb010','oneplus','oneplus9',35000,11,'2021-12-25'); select * from MobileMaster;
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;