0% found this document useful (0 votes)
2 views

SQL Masterclass

This document provides a step-by-step guide for creating a database in MySQL using MySQL Workbench, including how to design the database structure and generate the SQL script. It also covers basic SQL data manipulation commands such as INSERT, UPDATE, and DELETE, as well as querying data with SELECT statements and various clauses. The document concludes by encouraging practice and experimentation with SQL to enhance skills.

Uploaded by

donjaydiscord
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL Masterclass

This document provides a step-by-step guide for creating a database in MySQL using MySQL Workbench, including how to design the database structure and generate the SQL script. It also covers basic SQL data manipulation commands such as INSERT, UPDATE, and DELETE, as well as querying data with SELECT statements and various clauses. The document concludes by encouraging practice and experimentation with SQL to enhance skills.

Uploaded by

donjaydiscord
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Let's start with creating a database. In MySQL, you can use MySQL Workbench to create a database.

Follow these steps:

1. Open MySQL Workbench and connect to your MySQL server.

2. In the top menu, select File > New Model > Create New Diagram.

3. Drag and drop tables onto the canvas to create your database structure.

4. Define the columns for each table and specify the relationships between them.

5. Save your diagram as an .mwb file.

Once you've created your database structure, you can create the actual database in MySQL. Follow
these steps:

1. In MySQL Workbench, select the menu option Server > Data Export.

2. Choose the database schema you want to create.

3. Select the output file path where you want to save the script.

4. Choose the SQL Script option and set the other options to default.

5. Click Next and review the summary.

6. Click Execute to generate the SQL script.

Now that you've created your database, it's time to start manipulating data. You can do this using SQL
queries. SQL is a language used to communicate with a database, and it's used to insert, update, and
delete data in tables.

Let's start with the basics of data manipulation. Here are some common SQL statements you'll use to
manipulate data in tables:

 INSERT INTO: Adds new data to a table.

 UPDATE: Modifies existing data in a table.

 DELETE: Removes data from a table.

Here's an example of an INSERT INTO statement:

INSERT INTO customers (first_name, last_name, email)

VALUES ('John', 'Doe', '[email protected]');

This statement adds a new record to the "customers" table with the first name, last name, and email of
"John", "Doe", and "[email protected]", respectively.

Here's an example of an UPDATE statement:

UPDATE customers SET email = '[email protected]'

WHERE first_name = 'Jane' AND last_name = 'Doe';


This statement modifies the email address of a customer with the first name "Jane" and last name "Doe"
to "[email protected]".

Here's an example of a DELETE statement:

DELETE FROM customers

WHERE last_name = 'Doe';

This statement removes all records from the "customers" table where the last name is "Doe".

Now that you know how to manipulate data, it's time to learn how to query data. Here are some
common SQL statements you'll use to query data from tables:

 SELECT: Retrieves data from a table.

 WHERE: Filters the data retrieved by a SELECT statement based on a condition.

 ORDER BY: Sorts the data retrieved by a SELECT statement based on a specified column.

 GROUP BY: Groups the data retrieved by a SELECT statement based on a specified column.

 JOIN: Combines data from multiple tables into a single result set.

Here's an example of a SELECT statement:

SELECT * FROM customers;

This statement retrieves all data from the "customers" table

Here's an example of a SELECT statement with a WHERE clause:

SELECT * FROM customers WHERE first_name = 'John';

This statement retrieves all data from the "customers" table where the first name is "John".

Here's an example of a SELECT statement with an ORDER BY clause:

SELECT * FROM customers ORDER BY last_name;

This statement retrieves all data from the "customers" table and sorts it by the last name column in
ascending order.

Here's an example of a SELECT statement with a GROUP BY clause:

SELECT country, COUNT(*) FROM customers GROUP BY country;

This statement retrieves the number of customers in each country by grouping the data by the country
column.

Finally, here's an example of a SELECT statement with a JOIN clause:

SELECT orders.order_id, customers.first_name, customers.last_name


FROM orders

JOIN customers

ON orders.customer_id = customers.customer_id;

This statement retrieves data from both the "orders" and "customers" tables by joining them on the
"customer_id" column.

Congratulations! You've completed the Beginner's Masterclass for SQL using MySQL. You now have the
basic knowledge you need to start working with MySQL and querying data from databases. Keep
practicing and experimenting with SQL to improve your skills!

You might also like