CREATE TABLE Book (
 BookId integer auto_increment Primary key,
 Title VARCHAR(255) not null, 
 Author VARCHAR (255),
 isbn varchar (50), 
 publication_year year
 );
 INSERT INTO book (title,author,isbn,publication_year)
VALUES('let us c','yashavant kanetkar','978-93-91392-99-4',2016),
('digital circuit and design','s salivahanan','978-93-259-6041-1',2020),
('organizational theory,desing and change','garetha r.jones','978-81-317-5416-0',2021),
('introductory microeconomics','sultan chand','978-93-89174-82-3',2018),
('technical communication principle and practic','meenakshi raman','0-19-806529-9',2017),
('office 2007 in simple steps','kogent solution inc','978-81-7722-784-0',2016),
('progrming in basic','e balagurusamy','0-07-460055-9',2017),
('human resource management','p.jyothi','0-19-807411-5',2018),
('computer fundamental','b.ram','978-81-224-2043-2', 2020),
('information practic','sumita arora','978-81-7700-242-3',2021),
('informatics practicwith python','preeti arora','978-93-90851-07-2',2016),
('money banking','nk sinha','978-81-904589-4-8',2020),
('mercantile law','m.c kuchhal','9788-1259-31249',2016),
('introductionto cobol','david m.collopy','81-297-0870-1',2020),
('c in depth','s.k.srivastav','978-81-8333-048-0',2019),
('software engineering','rajiv mall','978-93-88028-02-8',2018),
('data base system','nilesh shah','978-81-203-3236-2',2017),
('sofware testing','paul c.jorgensen','0-8493-7475-8',2016),
('cobol progrming','nancy stern','9971-51-150-9',2017),
('sofware architecture','len bass','978-93-325-0230-7',2018),
('computer system architecture','m.morris mano','978-81-317-0070-9', 2020),
('object oriented progrming','e balagurusamy','978-1-25-902993-6',2021),
('fortran 77','c.xavir','81-224-0670',2016),
('educational management','j.c.aggarwal','978-93-80011-62-2',2020),
('indian economics','manish kumar','978-93-539-4033-1',2016),
('fundamental of microprocessor','b.ram','327-428-594',2017),
('progrming java','e balagurusamy','978-0-07-014169-8',2018),
('data structure with c','lipschutz','978-0-07-070198-4',2019),
('data interpretation','arun shrma','978-1-25-900383-7',2018),
('computer fundamental','p.k sinha','81-7656-360-9',2016),
('cimple','susant k rout','978-0-07-026069-6',2017),
('jquery','david sills ','978-93-5004-098-0',2016),
('iiiustrated wpf','daniel m.soils','978-81-8489-744-9',2020),
('object oriented system','ali bahrami','978-0-07-026512-7',2020),
('introducing maya 7','dariush derakshani','81-265-0634-2',2020),
('cystem','susant k','978-0-07-015388-2',2021),
('big data analytics','g.sudha sadasivam','0-19-949722-2',2016),
('internet thing','arshdeep','978-81-7371-9547',2018),
('the data warehouse','margy ross','81-265-0889-2',2019),
('software engineering','mc graw','007-124778-5',2020),
('microprocessor','dhanpat','2327-4073-2324-6573',2021),
('computer dictionary','microsoft','978-81-203-2055-0',2018),
('software engineering','mc graw','007-124778-5',2019),
('induction syschronous','k murugesh','004-258-4-456',2018),
('operating system','peter b. galvin','005-45-6524',2019),
('mathmatic for economists','mehta madnani','81-7014-173-7',2020),
('artifical intelligence','dan w. patterson','81-203-077-1',2021),
('object orinted modeling','ignous','81-203-1046-2',2021),
('static geography','zamir alvi','978-81-7033-271-8',2016),
('object ORIENTED MODELING','MICHAEL R BALHA','978-81-317-1106-4',2016);


 select*from book;



CREATE TABLE Members (
 MemberID integer auto_increment primary key,
 Name VARCHAR(255) not null,
 email VARCHAR (255),
 join_date date
 );
 INSERT INTO members(name,email,join_date)
VALUES('yash','[email protected]', '2018-05-19'),
('aryan','[email protected]', '2019-06-20'),
('shankar','[email protected]','2020-05-17'),
('gaurav','[email protected]', '2021-08-19'),
('shyam','ss [email protected]','2019-06-20'),
('razahussain','[email protected]','2020-06-08'),
('randheer yadav','[email protected]','2018-12-23'),
('pushkar','[email protected]','2020-05-11'),
('abhisheak','[email protected]','2016-12-22'),
('sagarshyam','[email protected]','2017-12-31'),
('ramsingh','RAM S\@gmail.com','2017-12-05'),
('sweety yadav','[email protected]','2018-09-15'),
('tannushyam','[email protected]','2019-12-20'),
('deepsingh','[email protected]','2020-11-25'),
('nancyarora','[email protected]','2021-01-30'),
('ravi singh','[email protected]','2021-02-13'),
('sanjusharam','sanjusharam8788.com','2018-03-12'),
('punitakumari','[email protected]','2017-04-24'),
('shyam singh','[email protected]','2016-05-16'),
('diyaraj','[email protected]', '2021-06-17');


select*from members;


 
CREATE TABLE borrowing(
 Borrowing_ID integer auto_increment primary key,
 BookId integer,
 MemberID integer,
 Borrowdate date,
 Returndate date,
 foreign key (BookId)references book (BookId),
 foreign key (MemberID)references members(MemberID),
 check (returndate>borrowdate)
 );

INSERT INTO borrowing (bookId,memberId,borrowdate,returndate)
VALUES(25,20,'2021-06-17','2021-07-20'),
(40,15,'2016-05-15','2021-08-24'),
(10,15,'2018-07-17','2021-08-19'),
(23,15,'2020-08-14','2021-09-12'),
(35,19,'2019-02-28','2021-03-17'),
(10,12,'2017-03-30','2021-05-13'),
(10,08,'2019-04-22','2021-05-10'),
(09,06,'2020-07-19','2021-08-09'),
(14,04,'2017-08-18','2021-09-05'),
(33,18,'2016-07-12','2021-07-23');


select*from borrowing where memberId = 15;

select* from borrowing where bookId = 10;

select* from borrowing where borrowdate between' 2016-05-01' and '2016-07-31';


select*from book where publication_year =2018;

select*from members where join_date < '2018-06-01';
update book set publication_year = 2019 where bookId =3;
select*from book where bookId=3;
update borrowing set returndate=curdate()where Borrowing_ID=5;
delete from  members where name ='shyam';
select*from members;
 

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  
by

MySQL online editor

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.

About MySQL

MySQL is a open-source, free and very popular relational database management system which is developed, distributed and supported by Oracle corporation.

Key Features:

  • Open-source relational database management systems.
  • Reliable, very fast and easy to use database server.
  • Works on client-server model.
  • Highly Secure and Scalable
  • High Performance
  • High productivity as it uses stored procedures, triggers, views to write a highly productive code.
  • Supports large databases efficiently.
  • Supports many operating systems like Linux*,CentOS*, Solaris*,Ubuntu*,Windows*, MacOS*,FreeBSD* and others.

Syntax help

Commands

1. CREATE

CREATE TABLE table_name (
                column1 datatype,
                column2 datatype,
                ....);

Example

CREATE TABLE EMPLOYEE (
  empId INTEGER PRIMARY KEY,
  name TEXT NOT NULL,
  dept TEXT NOT NULL
);

2. ALTER

ALTER TABLE Table_name ADD column_name datatype;

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Dave', 'Sales');

3. TRUNCATE

TRUNCATE table table_name;

4. DROP

DROP TABLE table_name;

5. RENAME

RENAME TABLE table_name1 to new_table_name1; 

6. COMMENT

Single-Line Comments:

 --Line1;

Multi-Line comments:

   /* Line1,
   Line2 */

DML Commands

1. INSERT

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

Note: Column names are optional.

Example

INSERT INTO EMPLOYEE VALUES (0001, 'Ava', 'Sales');

2. SELECT

SELECT column1, column2, ...
FROM table_name
[where condition]; 

Example

SELECT * FROM EMPLOYEE where dept ='sales';

3. UPDATE

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition; 

Example

UPDATE EMPLOYEE SET dept = 'Sales' WHERE empId='0001'; 

4. DELETE

DELETE FROM table_name where condition;

Example

DELETE from EMPLOYEE where empId='0001'; 

Indexes

1. CREATE INDEX

  CREATE INDEX index_name on table_name(column_name);
  • To Create Unique index:
  CREATE UNIQUE INDEX index_name on table_name(column_name);

2. DROP INDEX

DROP INDEX index_name ON table_name;

Views

1. Create a View

Creating a View:
CREATE VIEW View_name AS 
Query;

2. How to call view

SELECT * FROM View_name;

3. Altering a View

ALTER View View_name AS 
Query;

4. Deleting a View

DROP VIEW View_name;

Triggers

1. Create a Trigger

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 } */

2. Drop a Trigger

DROP TRIGGER [IF EXISTS] trigger_name;

Stored Procedures

1. Create a Stored Procedure

CREATE PROCEDURE sp_name(p1 datatype)
BEGIN
/*Stored procedure code*/
END;

2. How to call Stored procedure

CALL sp_name;

3. How to delete stored procedure

DROP PROCEDURE sp_name;

Joins

1. INNER JOIN

SELECT * FROM TABLE1 INNER JOIN TABLE2 where condition;

2. LEFT JOIN

SELECT * FROM TABLE1 LEFT JOIN TABLE2 ON condition;

3. RIGHT JOIN

SELECT * FROM TABLE1 RIGHT JOIN TABLE2 ON condition;

4. CROSS JOIN

SELECT select_list from TABLE1 CROSS JOIN TABLE2;