Welcome to our comprehensive guide on SQL, focusing on the popular open-source database management system, MariaDB! Whether you're a beginner or an intermediate learner, we've got you covered. Let's get started!
MariaDB is a community-developed, open-source relational database management system that is compatible with MySQL and the official MySQL variant. It's a powerful tool for managing data and is widely used in various projects.
Why use MariaDB?
SQL (Structured Query Language) is a standard language for managing and manipulating databases. It allows you to create, modify, and query databases, making it essential for developers and data analysts.
CREATE DATABASE your_database;CREATE TABLE your_table (
id INT PRIMARY KEY,
name VARCHAR(255),
age INT
);PRIMARY KEY ensures each row in the table is unique.VARCHAR(255) is used for string data up to 255 characters.INT is used for integer data.To insert data into a table, use the INSERT INTO command:
INSERT INTO your_table (id, name, age) VALUES (1, 'John', 30);To retrieve data from a table, use the SELECT command:
SELECT * FROM your_table;To update data in a table, use the UPDATE command:
UPDATE your_table SET age = 31 WHERE id = 1;To delete data from a table, use the DELETE command:
DELETE FROM your_table WHERE id = 1;DELETE command.Joins allow you to combine rows from two or more tables based on a related column:
SELECT users.name, orders.order_date
FROM users
JOIN orders ON users.id = orders.user_id;Stored Procedures are precompiled collections of SQL statements that can be executed as a single unit:
CREATE PROCEDURE update_user(IN id INT, IN new_age INT)
BEGIN
UPDATE users SET age = new_age WHERE id = id;
END;CREATE DATABASE users_and_orders;
USE users_and_orders;
CREATE TABLE users (
id INT PRIMARY KEY,
name VARCHAR(255),
email VARCHAR(255)
);
CREATE TABLE orders (
id INT PRIMARY KEY,
user_id INT,
order_date DATE,
total_amount DECIMAL(10,2)
);INSERT INTO users (id, name, email) VALUES (1, 'John Doe', 'john@example.com');
INSERT INTO orders (id, user_id, order_date, total_amount) VALUES (1, 1, '2022-01-01', 100.00);
SELECT * FROM users;
SELECT * FROM orders;
SELECT u.name, o.order_date, o.total_amount FROM users AS u
JOIN orders AS o ON u.id = o.user_id;Which SQL command creates a database?
What is a stored procedure in SQL?
We hope you enjoyed learning about MariaDB and SQL! Stay tuned for more tutorials on CodeYourCraft. Happy coding! 💻🎉