MySQL is an open-source relational database management system (RDBMS) based on Structured Query Language (SQL). It is widely used to store and manage data for various applications, from small websites to large-scale enterprise applications.
? Open Source ? Relational ? Scalable ⚡ High Performance ? Secure
name or email).Common SQL statements you will use with MySQL:
CREATE DATABASE – Defines a new database.USE – Switches to the specified database.CREATE TABLE – Creates a new table with columns and data types.INSERT INTO – Adds new records to a table.SELECT – Retrieves data from one or more tables.
-- Creating a database
CREATE DATABASE my_database;
-- Selecting a database
USE my_database;
-- Creating a table named 'users'
CREATE TABLE users (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
email VARCHAR(100)
);
-- Inserting data into the 'users' table
INSERT INTO users (name, email) VALUES ('John Doe', 'john.doe@example.com');
-- Querying all rows from the 'users' table
SELECT * FROM users;
This example demonstrates how to create a simple company database to store employee information.
-- Creating a database named 'company'
CREATE DATABASE company;
-- Using the 'company' database
USE company;
-- Creating an 'employees' table
CREATE TABLE employees (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
position VARCHAR(100),
salary DECIMAL(10, 2)
);
-- Inserting data into 'employees' table
INSERT INTO employees (name, position, salary)
VALUES ('Alice Johnson', 'Software Engineer', 70000.00);
-- Query to get all employees
SELECT * FROM employees;
CREATE DATABASE: Defines a new database (for example, company).USE: Switches to the specified database so that subsequent commands run in that context.CREATE TABLE: Defines a new table with specific columns and data types.INSERT INTO: Adds new records (rows) to a table.SELECT: Retrieves data from one or more tables, based on the query.When you run the final SELECT * FROM employees; query in a MySQL client, you will see a result table showing all employees, including the record for Alice Johnson that you inserted.
library database with a books table).NOT NULL or DEFAULT values on different columns.UPDATE and then verify the change with SELECT.DELETE and confirm it is removed.