1. Importance of Database Structure
1. A proper database structure is crucial for any data analysis project.
2. It keeps data organized, accessible, and easy to query.
2. Introduction to SQL
SQL (Structured Query Language) is the standard language for managing and manipulating
relational databases.
Basic SQL Commands:
SELECT: Retrieves data from a database.
Example: SELECT * FROM customers;
FROM: Specifies the table to retrieve data from.
WHERE: Sets conditions to filter data.
Example: SELECT * FROM customers WHERE age > 30;
LIMIT: Restricts the number of records returned by a query.
Example: SELECT * FROM customers LIMIT 5;
3. Creating a Database
The CREATE DATABASE command is used to create a new database.
Example: CREATE DATABASE my_database;
4. Creating Tables in a Database
, Tables can be created within a database using the CREATE TABLE command.
The structure includes:
Column names
Data types
Constraints (such as primary keys)
Example: Creating a customers table
CREATE TABLE customers (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50),
email VARCHAR(50),
age INT,
created_at TIMESTAMP
);
Explanation:
1. id: Integer, serves as the primary key and auto-increments with each new record.
2. name and email: Strings (VARCHAR) with a maximum length of 50 characters.
3. age: Integer, used to store the age of the customer.
4. created_at: Timestamp, records the date and time each entry is added.
5. Basic Data Manipulation Commands
INSERT INTO: Adds new records to a table.