SQL Tutorial: CRM System Project 🎯

beginner
19 min

SQL Tutorial: CRM System Project 🎯

Welcome to our SQL Tutorial! In this comprehensive guide, we'll be building a CRM (Customer Relationship Management) System using SQL. By the end of this tutorial, you'll have a solid understanding of SQL and how to use it in a real-world application.

Let's start with the basics. SQL (Structured Query Language) is a language used to communicate with databases. It allows us to create, read, update, and delete data in a structured way.

Creating a Database 📝

Before we can start, we need to create a database. In SQL, this is done using the CREATE DATABASE command.

sql
CREATE DATABASE crm;

Now, let's select our database:

sql
USE crm;

Tables 📝

Tables are where we store our data. In our CRM system, we'll need tables for Customers, Orders, and Products.

sql
CREATE TABLE Customers ( id INT PRIMARY KEY, name VARCHAR(100), email VARCHAR(100), phone VARCHAR(15) ); CREATE TABLE Products ( id INT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10, 2) ); CREATE TABLE Orders ( id INT PRIMARY KEY, customer_id INT, product_id INT, quantity INT, FOREIGN KEY (customer_id) REFERENCES Customers(id), FOREIGN KEY (product_id) REFERENCES Products(id) );

Inserting Data 💡

Now that we have our tables, let's insert some data.

sql
INSERT INTO Customers (id, name, email, phone) VALUES (1, 'John Doe', 'john.doe@example.com', '123-456-7890'); INSERT INTO Products (id, name, price) VALUES (1, 'Product 1', 10.99); INSERT INTO Orders (id, customer_id, product_id, quantity) VALUES (1, 1, 1, 2);

Querying Data 📝

We can query our data using SELECT statements.

sql
SELECT * FROM Customers; SELECT * FROM Products; SELECT * FROM Orders;

Joining Tables 💡

We can join tables to get more specific data.

sql
SELECT Customers.name, Orders.quantity FROM Customers JOIN Orders ON Customers.id = Orders.customer_id;

Updating Data 💡

We can update data using the UPDATE command.

sql
UPDATE Customers SET email = 'john.doe@newemail.com' WHERE id = 1;

Deleting Data 💡

We can delete data using the DELETE command.

sql
DELETE FROM Orders WHERE id = 1;

Quiz 📝

Quick Quiz
Question 1 of 1

What does SQL stand for?

Quick Quiz
Question 1 of 1

What does the `CREATE DATABASE` command do?