0% found this document useful (0 votes)
4 views4 pages

MySQL Guide Part1

The document is a complete guide to MySQL, covering essential commands such as creating databases and tables, inserting rows, and using constraints. It provides syntax examples and expected outputs for each command. Key functionalities include creating databases, inserting single and multiple rows, and retrieving data with conditions.
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)
4 views4 pages

MySQL Guide Part1

The document is a complete guide to MySQL, covering essential commands such as creating databases and tables, inserting rows, and using constraints. It provides syntax examples and expected outputs for each command. Key functionalities include creating databases, inserting single and multiple rows, and retrieving data with conditions.
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
You are on page 1/ 4

MySQL Complete Guide

1. CREATE DATABASE

Definition:

Creates a new database in MySQL.

Syntax:

CREATE DATABASE dbname;

Example:

CREATE DATABASE School;

Expected Output:

Query OK, 1 row affected

2. CREATE TABLE

Definition:

Creates a new table inside a database.

Syntax:

CREATE TABLE table_name (

column1 datatype,

column2 datatype,

...

);

Example:

CREATE TABLE Students (

ID INT PRIMARY KEY,

Name VARCHAR(100),

Age INT

);
MySQL Complete Guide

Expected Output:

Query OK, 0 rows affected

3. INSERT ROW

Definition:

Adds a single row of data to a table.

Syntax:

INSERT INTO table_name (col1, col2) VALUES (val1, val2);

Example:

INSERT INTO Students (ID, Name, Age) VALUES (1, 'Ali', 18);

Expected Output:

Query OK, 1 row affected

4. INSERT MULTIPLE ROWS

Definition:

Inserts several rows in a single query.

Syntax:

INSERT INTO table_name (col1, col2) VALUES

(val1a, val2a),

(val1b, val2b);

Example:

INSERT INTO Students (ID, Name, Age) VALUES

(2, 'Sara', 20),

(3, 'John', 17);

Expected Output:
MySQL Complete Guide

Query OK, 2 rows affected

5. CONSTRAINTS

Definition:

Used to enforce rules on data like uniqueness, no nulls, referential integrity.

Syntax:

PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, DEFAULT

Example:

CREATE TABLE Courses (

CourseID INT PRIMARY KEY,

CourseName VARCHAR(50) NOT NULL,

CreditHours INT CHECK (CreditHours > 0)

);

Expected Output:

Query OK, 0 rows affected

6. SELECT with WHERE

Definition:

Retrieves rows that match a condition.

Syntax:

SELECT * FROM table_name WHERE condition;

Example:

SELECT * FROM Students WHERE Age > 18;

Expected Output:

+----+-------+-----+
MySQL Complete Guide

| ID | Name | Age |

+----+-------+-----+

| 2 | Sara | 20 |

+----+-------+-----+

You might also like