Introduction to SQL
SQL stands of Structured Query Language. It is programming language that is used to manage data in a relational data management system that was introduced in the 1970s. It was developed at IBM by Donald D. Chamberlin and Raymond F. Boyce after learning about the relational model from Edgar F. Codd.
SQL was formerly knowns as SEQUEL, but later shortened SQL. SQL allows you access and manipulate databases. Oracle was the first vendor to offer a SQL management system.
SQL is used by software developers, data analysts, and data administers. These careers work with manipulating large amounts of data, and what why SQL is a great language to work with.
How does SQL work
SQL is a language used to communicate with databases. It’s used to create, modify, retrieve, and manipulate data in relational databases.
SQL can be used to create tables and interact with data in those tables.
SQL use a server to process requests for data and then it will send back results. A user will send a request with SQL query. The query is sent to the SQL server. The server searches the database. The results are returned.
SQL Query Received: A user sends a query and the SQL engine receives it from the application.
Query Parsing: The SQL engine's parser checks the syntax of the query to make sure that it’s valid. Once it's valid, the parser converts it into an internal representation called a parse tree.
Query Optimization: The optimizer checks out the query and decides the best way to execute it. The main goal it is minimize time and resources that's needed to run this query.
Query Execution: The query is executed and results are received according to the execution plan.
Data Retrieval and Storage Access: The storage engine interacts with the physical storage to get data and possibly update records.
Return Results: The SQL engine sends the results back to the user or application.
SQL Database Management Systems can be used with different Database Management Systems that offer their own way of using of SQL.
- MySQL: An open-source relational database management system.
- PostgreSQL: An advanced open-source database known for its ability to cover large databases.
- SQL Server: A relational database developed by Microsoft.
- Oracle: A widely used commercial relational database management system.
Datatypes
SQL Data Types
SQL databases support a variety of data types to define the type of data each column in a table can hold.
SQL Comments
/* This is a multi-line
comment in SQL. */
-- This is a single-line comment in SQL.
SQL Commands
SQL commands are case-insensitive and are written uppercase for clarity.
Statements end with a semicolon but it's not it is not needed.
There are four main key commands used in SQL.
SELECT is used to retrieve data.
DELETE is used to remove data.
INSERT is used to add new data.
UDPDATE is used to modify data.
-- Create Sales table
CREATE TABLE Sales (
sale_id INT PRIMARY KEY,
product_id INT,
quantity_sold INT,
sale_date DATE,
total_price DECIMAL(10, 2)
);
-- Insert sample data into Sales table
INSERT INTO Sales (sale_id, product_id, quantity_sold, sale_date, total_price) VALUES
(1, 101, 5, '2024-01-01', 2500.00),
(2, 102, 3, '2024-01-02', 900.00),
(3, 103, 2, '2024-01-02', 60.00),
(4, 104, 4, '2024-01-03', 80.00),
(5, 105, 6, '2024-01-03', 90.00);
Conclusion
Conclusion
SQL is a great programming tool for managing relational databases. You can create, manipulate, and retrieve data while keeping the data safe with great performance. SQL is the preferred language for relational database management if you are working with small or large databases.
Sources
Top comments (0)