DEV Community

Cover image for Introduction to SQL
Whitley Legard Antoine
Whitley Legard Antoine

Posted on • Edited on

Introduction to SQL

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.

  1. SQL Query Received: A user sends a query and the SQL engine receives it from the application.

  2. 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.

  3. 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.

  4. Query Execution: The query is executed and results are received according to the execution plan.

  5. Data Retrieval and Storage Access: The storage engine interacts with the physical storage to get data and possibly update records.

  6. 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.

  1. MySQL: An open-source relational database management system.
  2. PostgreSQL: An advanced open-source database known for its ability to cover large databases.
  3. SQL Server: A relational database developed by Microsoft.
  4. Oracle: A widely used commercial relational database management system.

Image description

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.

Image description

SQL Comments

/* This is a multi-line
comment in SQL. */

-- This is a single-line comment in SQL.
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

Output
Image description

Image description

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

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay