Database - MySQL
Database - MySQL
Database
Is a collection of data stored in a format that can easily be accessed
DBMS is used to manage Database
Categories
1. Relational : Relation stores data in tables linked together
2. Not Relational (No Sql)
Examples of RDBMS
1. MySQL
2. SQLServer
3. Oracle
No Relational
No tables and relationships
Don’t understand SQL
MySQL
Introduction to MySQL
1. Relational Database
2. Data Types
● MySQL supports various data types to store different kinds of data (e.g.,
integers, strings, dates, decimals).
● Choosing the appropriate data type helps optimize storage and ensures data
integrity.
4. Key Concepts
● Primary Key: A unique identifier for each row within a table (usually an
auto-incrementing integer).
● Foreign Key: Creates a link between two tables, enforcing data integrity.
● Indexes: Speed up data retrieval by creating an index on frequently used
columns.
Data Types
INT: Stores whole numbers (positive, negative, or zero) of varying sizes depending
on the specific implementation (often 32-bit integers).
SMALLINT: Stores smaller whole numbers, typically using less storage space than
INT.
DECIMAL: Stores numbers with decimal precision for accurate calculations involving
money or other precise measurements.
TEXT: Stores large amounts of text data (often used for long descriptions or content).
BLOB (Binary Large OBject): Stores large binary data (e.g., images, audio, files).
^ beginning
$ end
| logical or
[abcd]e —any coming before e
IS NULL: SELECT * FROM customer WHERE phone IS NULL
SORTING
ORDER BY first_name DESC
LIMIT :
SELECT * FROM customer LIMIT 10
Should always come at the end
Offset
SELECT * FROM customer LIMIT 3 10 —- offset is 3, then selects 10 records
Creating a Table
CREATE TABLE ‘clients’ (
‘Client_id’ int(11) NOT NULL,
‘Name’ varchar(50) NOT NULL,
‘Address’ varchar(50) NOT NULL,
‘Phone’ varch(20) DEFAULT NULL,
PRIMARY KEY (‘client_id’)
)