The post What is SQL ? appeared first on So Called Happenings.
]]>
is a standard language for storing, manipulating and retrieving data
in databases.
SQL is a standard Database language which is used to create, maintain and retrieve the data from relational databases like MySQL, Oracle, SQL Server, PostGre, etc
RDBMS stands for Relational Database Management System.
It 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 entries and it consists of columns and rows.
A database most often contains one or more tables. Each table is identified by a name.
Most of the actions you need to perform on a database are done with SQL statements.
Some database systems require a semicolon at the end of each SQL statement.
Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
select
is the same as SELECT
SELECT
– extracts data from a databaseUPDATE
– updates data in a databaseDELETE
– deletes_data from a databaseINSERT INTO
– inserts new_data into a databaseCREATE DATABASE
– creates a new databaseALTER DATABASE
– modifies a databaseCREATE TABLE
– creates a new tableALTER TABLE
– modifies a tableDROP TABLE
– deletes a tableCREATE INDEX
– creates an index (search key)DROP INDEX
– deletes an indexThe SELECT
statement is used to select data from a database.
The data returned is stored in a result table called the result-set.
SELECT column1, column2, …
FROM table_name;
Here, column1, column2, … are the field names of the table you want to select data from. To select all the fields available in the table, use the following syntax:
SELECT * FROM table_name;
The SELECT DISTINCT
statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.
SELECT DISTINCT column1, column2, …
FROM table_name;
The following SQL statement lists the number of different (distinct) customer countries:
SELECT COUNT(DISTINCT Country) FROM Customers;
Note: The example above will not work in Firefox! Because COUNT(DISTINCT column_name) is not supported in Microsoft Access databases. Firefox is using Microsoft Access in our examples.
Here is the workaround for MS Access:
SELECT Count(*) AS DistinctCountries
FROM (SELECT DISTINCT Country FROM Customers);
The WHERE
clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
SELECT column1, column2, …
FROM table_name
WHERE condition;
Note: The WHERE
clause is not only used in SELECT
statements, it is also used in UPDATE
, DELETE
, etc.!
The following operators can be used in the WHERE
clause:
Operator | Description | |
---|---|---|
= | Equal |
> | Greater than | |
< | Less than | |
>= | Greater than or equal | |
<= | Less than or equal | |
<> | Not equal. Note: In some versions of SQL this operator may be written as != | |
BETWEEN | Between a certain range | |
LIKE | Search for a pattern | |
IN | To specify multiple possible values for a column |
The post What is SQL ? appeared first on So Called Happenings.
]]>