0% found this document useful (0 votes)
3 views15 pages

Sql-Structured Query Language What Is SQL?

SQL (Structured Query Language) is a programming language used for managing and processing data in relational databases, allowing users to create, update, and retrieve data efficiently. It is widely used due to its ease of integration with various programming languages and its standardized commands for database manipulation. SQL commands are categorized into several types, including Data Definition Language (DDL), Data Query Language (DQL), and Data Manipulation Language (DML), among others.

Uploaded by

dabiodun200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

Sql-Structured Query Language What Is SQL?

SQL (Structured Query Language) is a programming language used for managing and processing data in relational databases, allowing users to create, update, and retrieve data efficiently. It is widely used due to its ease of integration with various programming languages and its standardized commands for database manipulation. SQL commands are categorized into several types, including Data Definition Language (DDL), Data Query Language (DQL), and Data Manipulation Language (DML), among others.

Uploaded by

dabiodun200
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

SQL- STRUCTURED QUERY LANGUAGE

What is SQL?

Structured query language (SQL) is a programming language for storing and processing information in a
relational database. A relational database stores information in tabular form, with rows and columns
representing different data attributes and the various relationships between the data values. You can use
SQL statements to store, update, remove, search, and retrieve information from the database. You can
also use SQL to maintain and optimize database performance.
Why is SQL important?

Structured query language (SQL) is a popular query language that is frequently used in all types of
applications. Data analysts and developers learn and use SQL because it integrates well with different
programming languages. For example, they can embed SQL queries with the Java programming language
to build high-performing data processing applications with major SQL database systems such as Oracle or
MS SQL Server. SQL is also fairly easy to learn as it uses common English keywords in its statements

History of SQL

SQL was invented in the 1970s based on the relational data model. It was initially known as the structured
English query language (SEQUEL). The term was later shortened to SQL. Oracle, formerly known as
Relational Software, became the first vendor to offer a commercial SQL relational database management
system.

What are the components of a SQL system?

Relational database management systems use structured query language (SQL) to store and manage data.
The system stores multiple database tables that relate to each other. MS SQL Server, MySQL, or MS
Access are examples of relational database management systems. The following are the components of
such a system.

SQL table

A SQL table is the basic element of a relational database. The SQL database table consists of rows and
columns. Database engineers create relationships between multiple database tables to optimize data
storage space.

For example, the database engineer creates a SQL table for products in a store:
Product ID Product Name Color ID
0001 Mattress Color 1
0002 Pillow Color 2

Then the database engineer links the product table to the color table with the Color ID:

Color ID Color Name


Color 1 Blue
Color 2 Red

SQL statements

SQL statements, or SQL queries, are valid instructions that relational database management systems
understand. Software developers build SQL statements by using different SQL language elements. SQL
language elements are components such as identifiers, variables, and search conditions that form a correct
SQL statement.

For example, the following SQL statement uses a SQL INSERT command to store Mattress Brand
A, priced $499, into a table named Mattress_table, with column names brand_name and cost:

INSERT INTO Mattress_table (brand_name, cost)

VALUES(‘A’,’499’);

Stored procedures

Stored procedures are a collection of one or more SQL statements stored in the relational database.
Software developers use stored procedures to improve efficiency and performance. For example, they can
create a stored procedure for updating sales tables instead of writing the same SQL statement in different
applications.

How does SQL work?


Structured query language (SQL) implementation involves a server machine that processes the database
queries and returns the results. The SQL process goes through several software components, including the
following.

Parser

The parser starts by tokenizing, or replacing, some of the words in the SQL statement with special
symbols. It then checks the statement for the following:

Correctness

The parser verifies that the SQL statement conforms to SQL semantics, or rules, that ensure the
correctness of the query statement. For example, the parser checks if the SQL command ends with a semi-
colon. If the semi-colon is missing, the parser returns an error.

Authorization

The parser also validates that the user running the query has the necessary authorization to manipulate the
respective data. For example, only admin users might have the right to delete data.

Relational engine

The relational engine, or query processor, creates a plan for retrieving, writing, or updating the
corresponding data in the most effective manner. For example, it checks for similar queries, reuses
previous data manipulation methods, or creates a new one. It writes the plan in an intermediate-level
representation of the SQL statement called byte code. Relational databases use byte code to efficiently
perform database searches and modifications.

Storage engine

The storage engine, or database engine, is the software component that processes the byte code and runs
the intended SQL statement. It reads and stores the data in the database files on physical disk storage.
Upon completion, the storage engine returns the result to the requesting application.

What are SQL commands?


Structured query language (SQL) commands are specific keywords or SQL statements that developers use
to manipulate the data stored in a relational database. You can categorize SQL commands as follows.

Data definition language

Data definition language (DDL) refers to SQL commands that design the database structure. Database
engineers use DDL to create and modify database objects based on the business requirements. For
example, the database engineer uses the CREATE command to create database objects such as tables,
views, and indexes.

Data query language

Data query language (DQL) consists of instructions for retrieving data stored in relational databases.
Software applications use the SELECT command to filter and return specific results from a SQL table.

Data manipulation language

Data manipulation language (DML) statements write new information or modify existing records in a
relational database. For example, an application uses the INSERT command to store a new record in the
database.

Data control language

Database administrators use data control language (DCL) to manage or authorize database access for
other users. For example, they can use the GRANT command to permit certain applications to manipulate
one or more tables.

Transaction control language

The relational engine uses transaction control language (TCL) to automatically make database changes.
For example, the database uses the ROLLBACK command to undo an erroneous transaction.

What are SQL standards?


SQL standards are a set of formally defined guidelines of the structured query language (SQL). The
American National Standards Institute (ANSI) and International Organization for Standardization (ISO)
adopted the SQL standards in 1986. Software vendors use the ANSI SQL standards to build SQL
database software for developers.

What is SQL injection?

SQL injection is a cyberattack that involves tricking the database with SQL queries. Hackers use SQL
injection to retrieve, modify, or corrupt data in a SQL database. For example, they might fill in a SQL
query instead of a person's name in a submission form to carry out a SQL injection attack.

What is MySQL?

MySQL is an open-source relational database management system offered by Oracle. Developers can
download and use MySQL without paying a licensing fee. They can install MySQL on different operating
systems or cloud servers. MySQL is a popular database system for web applications.

SQL vs. MySQL

Structured query language (SQL) is a standard language for database creation and manipulation. MySQL
is a relational database program that uses SQL queries. While SQL commands are defined by
international standards, the MySQL software undergoes continual upgrades and improvements.

What is NoSQL?

NoSQL refers to non-relational databases that don't use tables to store data. Developers store information
in different types of NoSQL databases, including graphs, documents, and key-values. NoSQL databases
are popular for modern applications because they are horizontally scalable. Horizontal scaling means
increasing the processing power by adding more computers that run NoSQL software.

SQL vs. NoSQL

Structured query language (SQL) provides a uniform data manipulation language, but NoSQL
implementation is dependent on different technologies. Developers use SQL for transactional and
analytical applications, whereas NoSQL is suitable for responsive, heavy-usage applications.

What is a SQL server?


SQL Server is the official name of Microsoft's relational database management system that manipulates
data with SQL. The MS SQL Server has several editions, and each is designed for specific workloads and
requirements.

What is SQL Syntax?

SQL syntax is a unique set of rules and guidelines to be followed while writing SQL statements. This
tutorial gives you a quick start with SQL by listing all the basic SQL Syntax.

All the SQL statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE,
ALTER, DROP, CREATE, USE, SHOW and all the statements end with a semicolon (;).

Case Sensitivity

The most important point to be noted here is that SQL is case insensitive, which
means SELECT and Select have same meaning in SQL statements. Whereas, MySQL makes difference
in table names. So, if you are working with MySQL, then you need to give table names as they exist in
the database.

SQL Statements

This tutorial lists down various SQL statements. Most of them are compatible with MySQL, Oracle,
Postgres and SQL Server databases.

All the SQL statements require a semicolon (;) at the end of each statement. Semicolon is the standard
way to separate different SQL statements which allows to include multiple SQL statements in a single
line.

SQL CREATE DATABASE Statement

To store data within a database, you first need to create it. This is necessary to individualize the data
belonging to an organization.

You can create a database using the following syntax −

CREATE DATABASE database_name;


Let us try to create a sample database sampleDB in SQL using the CREATE DATABASE statement −
CREATE DATABASE sampleDB
SQL USE Statement

Once the database is created, it needs to be used in order to start storing the data accordingly. Following is
the syntax to change the current location to required database −

USE database_name;
We can set the previously created sampleDB as the default database by using the USE statement in SQL

USE sampleDB;
SQL DROP DATABASE Statement

If a database is no longer necessary, you can also delete it. To delete/drop a database, use the following
syntax −

DROP DATABASE database_name;


You can also drop the sampleDB database by using the DROP DATABASE statement in SQL −

DROP DATABASE sampleDB;


SQL CREATE TABLE Statement

In an SQL driven database, the data is stored in a structured manner, i.e. in the form of tables. To create a
table, following syntax is used −
Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 1 to server version: 5.0.27-community-nt

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| acc317 |

| mysql |

| phpmyadmin |

| test |

+--------------------+

5 rows in set (0.00 sec)

mysql> SHOW
-> DATABASES

->

->

->

->

->

->

-> ;

+--------------------+

| Database |

+--------------------+

| information_schema |

| acc317 |

| mysql |

| phpmyadmin |

| test |

+--------------------+

5 rows in set (0.00 sec)

mysql> CREATE DATABASE hnd com sc;


ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'com sc' at line 1

mysql> CREATE DATABASE hndComSc;

Query OK, 1 row affected (0.03 sec)

mysql> SHOW DATABASES;

+--------------------+

| Database |

+--------------------+

| information_schema |

| acc317 |

| hndcomsc |

| mysql |

| phpmyadmin |

| test |

+--------------------+

6 rows in set (0.00 sec)

mysql> SHOW TABLES;

ERROR 1046 (3D000): No database selected

mysql> USE HNDCOMSC;


Database changed

mysql> SHOW TABLES;

Empty set (0.00 sec)

mysql> CREATE TABLE stdtb(

-> id int(20) not null,

-> name char(255) not null,

-> age int(50) not null,

-> address varchar(255),

-> salary varchar(50) not null

-> );

Query OK, 0 rows affected (0.08 sec)

mysql> SHOW TABLES;

+--------------------+

| Tables_in_hndcomsc |

+--------------------+

| stdtb |

+--------------------+

1 row in set (0.00 sec)


mysql> DESC STDTB;

+---------+--------------+------+-----+---------+-------+

| Field | Type | Null | Key | Default | Extra |

+---------+--------------+------+-----+---------+-------+

| id | int(20) | NO | | | |

| name | char(255) | NO | | | |

| age | int(50) | NO | | | |

| address | varchar(255) | YES | | NULL | |

| salary | varchar(50) | NO | | | |

+---------+--------------+------+-----+---------+-------+

5 rows in set (0.05 sec)

mysql> INSERT INTO stdtb VALUES (14567, "Amadi Emmanuel", 30, "Osogbo", "187,500.80");

Query OK, 1 row affected (0.01 sec)

mysql> SELECT * from STDTD;

ERROR 1146 (42S02): Table 'hndcomsc.stdtd' doesn't exist

mysql> SELECT * from STDTB;

+-------+----------------+-----+---------+------------+

| id | name | age | address | salary |

+-------+----------------+-----+---------+------------+
| 14567 | Amadi Emmanuel | 30 | Osogbo | 187,500.80 |

+-------+----------------+-----+---------+------------+

1 row in set (0.00 sec)

mysql> INSERT INTO stdtb VALUES

-> (14568, "Anah Joy", 49, "Sambisa", "205,900.80"),

-> (14569, "Ogunmayin Ayomide", 32, "Ajegunle", "315,100.75"),

-> (14570, "Olise Mark", 55, "Mushin", "288,900.45"),

-> (14571, "Ogunyemi Deborah", 85, " ", "400,900.45")

-> ;

Query OK, 4 rows affected (0.01 sec)

Records: 4 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM stdtb;

+-------+-------------------+-----+----------+------------+

| id | name | age | address | salary |

+-------+-------------------+-----+----------+------------+

| 14567 | Amadi Emmanuel | 30 | Osogbo | 187,500.80 |

| 14568 | Anah Joy | 49 | Sambisa | 205,900.80 |

| 14569 | Ogunmayin Ayomide | 32 | Ajegunle | 315,100.75 |

| 14570 | Olise Mark | 55 | Mushin | 288,900.45 |


| 14571 | Ogunyemi Deborah | 85 | | 400,900.45 |

+-------+-------------------+-----+----------+------------+

5 rows in set (0.00 sec)

mysql>

You might also like