0% found this document useful (0 votes)
2 views3 pages

MySQL - Revision Tour - Notes

The document provides an overview of MySQL commands categorized into Data Definition Language (DDL), Data Query Language (DQL), and Data Manipulation Language (DML). It includes syntax and examples for creating and altering databases and tables, querying data, and manipulating records. Key commands covered include CREATE, DROP, SELECT, INSERT, DELETE, and UPDATE.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

MySQL - Revision Tour - Notes

The document provides an overview of MySQL commands categorized into Data Definition Language (DDL), Data Query Language (DQL), and Data Manipulation Language (DML). It includes syntax and examples for creating and altering databases and tables, querying data, and manipulating records. Key commands covered include CREATE, DROP, SELECT, INSERT, DELETE, and UPDATE.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MySQL Revision Tour Class – XII

1. Data Definition Language (DDL)

a. CREATE DATABASE
Purpose: Creates a new database.

 Syntax:

CREATE DATABASE database_name;

 Example:

CREATE DATABASE SchoolDB;

b. CREATE TABLE
Purpose: Creates a new table inside a database.

 Syntax:

CREATE TABLE table_name (


column1 datatype(size),
column2 datatype(size),
...
);

 Example:

CREATE TABLE Students (


RollNo INT,
Name VARCHAR(50),
Age INT,
Grade CHAR(1)
);

c. DROP
Purpose: Deletes a database or a table permanently.

 Syntax:

DROP DATABASE database_name;


DROP TABLE table_name;

 Example:

DROP TABLE Students;

d. ALTER
Purpose: Modifies the structure of an existing table.

 Syntax:
- Add a column:
ALTER TABLE table_name ADD column_name datatype;

- Modify a column:
ALTER TABLE table_name MODIFY column_name new_datatype;

- Drop a column:
ALTER TABLE table_name DROP COLUMN column_name;

 Example:

ALTER TABLE Students ADD Email VARCHAR(100);

2. Data Query Language (DQL)

a. SELECT, FROM
Purpose: Retrieve data from a table.

 Syntax:

SELECT column1, column2 FROM table_name;

 Example:

SELECT Name, Age FROM Students;

b. WHERE with relational operators


Purpose: Filters records based on condition(s).
Relational operators: =, >, <, >=, <=, <>, !=

 Syntax:

SELECT * FROM table_name WHERE condition;

 Example:

SELECT * FROM Students WHERE Age > 15;

c. BETWEEN
Purpose: Checks if a value is within a range (inclusive).

 Syntax:

SELECT * FROM table_name WHERE column_name BETWEEN value1 AND value2;

 Example:

SELECT * FROM Students WHERE Age BETWEEN 12 AND 16;

d. Logical Operators: AND, OR, NOT


Purpose: Combine multiple conditions.

 Syntax:

SELECT * FROM table_name WHERE condition1 AND/OR/NOT condition2;

 Example:
SELECT * FROM Students WHERE Age > 12 AND Grade = 'A';

e. IS NULL and IS NOT NULL


Purpose: Test for empty (NULL) or non-empty values.

 Syntax:

SELECT * FROM table_name WHERE column_name IS NULL;


SELECT * FROM table_name WHERE column_name IS NOT NULL;

 Example:

SELECT * FROM Students WHERE Email IS NULL;

3. Data Manipulation Language (DML)

a. INSERT
Purpose: Inserts new records into a table.

 Syntax:

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

 Example:

INSERT INTO Students (RollNo, Name, Age, Grade) VALUES (1, 'Aman', 14, 'A');

b. DELETE
Purpose: Deletes one or more records from a table.

 Syntax:

DELETE FROM table_name WHERE condition;

 Example:

DELETE FROM Students WHERE RollNo = 1;

c. UPDATE
Purpose: Updates existing records in a table.

 Syntax:

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

 Example:

UPDATE Students SET Grade = 'B' WHERE Name = 'Aman';

You might also like