Relational Database Management System

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.

SQL DML and DDL

SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data Definition Language (DDL).

The query and update commands form the DML part of SQL:

  • SELECT – extracts data from a database
  • UPDATE – updates data in a database
  • DELETE – deletes data from a database
  • INSERT INTO – inserts new data into a database

The DDL part of SQL permits database tables to be created or deleted. It also defines indexes (keys), specifies links between tables, and imposes constraints between tables. The most important DDL statements in SQL are:

  • CREATE DATABASE – creates a new database
  • ALTER DATABASE – modifies a database
  • CREATE TABLE – creates a new table
  • ALTER TABLE – modifies a table
  • DROP TABLE – deletes a table
  • CREATE INDEX – creates an index (search key)
  • DROP INDEX – deletes an index

SQL SELECT Syntax

[cc lang=”SQL”]
SELECT column_name(s)
FROM table_name
[/cc]
and
[cc lang=”SQL”]
SELECT * FROM table_name
[/cc]

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

[cc lang=”SQL”]
SELECT DISTINCT column_name(s)
FROM table_name
[/cc]

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

[cc lang=”SQL”]
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
[/cc]

SQL uses single quotes around text values (most database systems will also accept double quotes).
However, numeric values should not be enclosed in quotes.

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

[cc lang=”SQL”]
SELECT * FROM Persons
WHERE FirstName=’Tove’
AND LastName=’Svendson’
[/cc]

Combining AND & OR
[cc lang=”SQL”]
SELECT * FROM Persons WHERE
LastName=’Svendson’
AND (FirstName=’Tove’ OR FirstName=’Ola’)
[/cc]

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.
[cc lang=”SQL”]
SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
[/cc]

SQL INSERT INTO Syntax
The INSERT INTO Statement is used to insert a new row in a table.
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:
[cc lang=”SQL”]
INSERT INTO table_name
VALUES (value1, value2, value3,…)
[/cc]

The second form specifies both the column names and the values to be inserted:
[cc lang=”SQL”]
INSERT INTO table_name (column1, column2, column3,…)
VALUES (value1, value2, value3,…)
[/cc]

SQL UPDATE Syntax
The UPDATE statement is used to update existing records in a table.
[cc lang=”SQL”]
UPDATE table_name
SET column1=value, column2=value2,…
WHERE some_column=some_value
[/cc]

SQL DELETE Syntax
The DELETE statement is used to delete rows in a table.
[cc lang=”SQL”]
DELETE FROM table_name
WHERE some_column=some_value
[/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *