0% found this document useful (0 votes)
27 views

What Can SQL Do?: SQL (Structured Query Language)

SQL is a standard language for querying, manipulating, and defining databases. It allows users to execute queries to retrieve, insert, update, and delete data from databases. SQL is used with Relational Database Management Systems (RDBMS) like MySQL, Oracle, and SQL Server which store data in tables that can be restructured and accessed using SQL statements. Common SQL statements include SELECT to retrieve data, INSERT to add new records, UPDATE to modify existing records, and DELETE to remove records.

Uploaded by

oskr_hh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

What Can SQL Do?: SQL (Structured Query Language)

SQL is a standard language for querying, manipulating, and defining databases. It allows users to execute queries to retrieve, insert, update, and delete data from databases. SQL is used with Relational Database Management Systems (RDBMS) like MySQL, Oracle, and SQL Server which store data in tables that can be restructured and accessed using SQL statements. Common SQL statements include SELECT to retrieve data, INSERT to add new records, UPDATE to modify existing records, and DELETE to remove records.

Uploaded by

oskr_hh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL (Structured Query Language)

SQL is a standard language for accessing and manipulating databases.

What Can SQL do?

 SQL can execute queries against a database


 SQL can retrieve data from a database
 SQL can insert records in a database
 SQL can update records in a database
 SQL can delete records from a database
 SQL can create new databases
 SQL can create new tables in a database
 SQL can create stored procedures in a database
 SQL can create views in a database
 SQL can set permissions on tables, procedures, and views

RDBMS
RDBMS stands for Relational Database Management System.

RDBMS is the basis for SQL, and for all modern database systems such as MS SQL Server, IBM DB2, Oracle,
MySQL, and Microsoft Access.

The data in RDBMS is stored in database objects called tables.

A table is a collection of related data entries and it consists of columns and rows.

Database Tables
A database most often contains one or more tables. Each table is identified by a name (e.g. "Customers" or
"Orders"). Tables contain records (rows) with data.

SQL Statements
Most of the actions you need to perform on a database are done with SQL statements.

SQL SELECT Syntax


SELECT column_name(s)
FROM table_name

and

SELECT * FROM table_name

The following SQL statement will select all the records in the "Persons" table:

SELECT * FROM Persons


Keep in Mind That...
SQL is not case sensitive. SELECT is the same as select.

The SQL SELECT DISTINCT Statement


In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes
you will want to list only the different (distinct) values in a table.

The DISTINCT keyword can be used to return only distinct (different) values.

SQL SELECT DISTINCT Syntax


SELECT DISTINCT column_name(s)
FROM table_name

The WHERE Clause 


The WHERE clause is used to extract only those records that fulfill a specified criterion.

SQL WHERE Syntax


SELECT column_name(s)
FROM table_name
WHERE column_name operator value

Operators Allowed in the WHERE Clause


With the WHERE clause, the following operators can be used:

Operator Description
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
LIKE Search for a pattern
IN To specify multiple possible values for a column

Note: In some versions of SQL the <> operator may be written as !=


The AND & OR Operators
The AND operator displays a record if both the first condition and the second condition is true.

The OR operator displays a record if either the first condition or the second condition is true.

Combining AND & OR


You can also combine AND and OR (use parenthesis to form complex expressions).

The ORDER BY Keyword


The ORDER BY keyword is used to sort the result-set by a specified column.

The ORDER BY keyword sort the records in ascending order by default.

If you want to sort the records in a descending order, you can use the DESC keyword.

SQL ORDER BY Syntax


SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC

The INSERT INTO Statement


The INSERT INTO statement is used to insert a new row in a table.

SQL INSERT INTO Syntax

It is possible to write the INSERT INTO statement in two forms.

The first form doesn't specify the column names where the data will be inserted, only their values:

INSERT INTO table_name


VALUES (value1, value2, value3,...)

The second form specifies both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3,...)


VALUES (value1, value2, value3,...)

The UPDATE Statement


The UPDATE statement is used to update existing records in a table.
SQL UPDATE Syntax
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records
that should be updated. If you omit the WHERE clause, all records will be updated!

The DELETE Statement


The DELETE statement is used to delete rows in a table.

SQL DELETE Syntax


DELETE FROM table_name
WHERE some_column=some_value

Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records
that should be deleted. If you omit the WHERE clause, all records will be deleted!

Delete All Rows


It is possible to delete all rows in a table without deleting the table. This means that the table structure,
attributes, and indexes will be intact:

DELETE FROM table_name

or

DELETE * FROM table_name

Note: Be very careful when deleting records. You cannot undo this statement!

You might also like