Introduction To SQL-1
Introduction To SQL-1
SQL constraints are used to specify rules for the data in a table.
If there is any violation between the constraint and the data action, the action is aborted by the
constraint.
Constraints can be specified when the table is created (inside the CREATE TABLE statement) or
after the table is created (inside the ALTER TABLE statement).
Introduction to SQL
Structure Query Language (SQL) is a programming language used for storing and managing data
in RDBMS. SQL was the first commercial language introduced for E.F Codd's Relational
model. Today almost all RDBMS (MySql, Oracle, Infomix, Sybase, MS Access) uses SQL as
the standard database language. SQL is used to perform all type of data operations in RDBMS.
Originally based upon relational algebra and tuple relational calculus, SQL consists of a data
definition language, data manipulation language, and Data Control Language. The scope of SQL
includes data insert, query, update and delete, schema creation and modification, and data access
control. Although SQL is often described as, and to a great extent is, a declarative language
(4GL), it also includes procedural elements.
SQL was one of the first commercial languages for Edgar F. Codd's relational model, as
described in his influential 1970 paper, "A Relational Model of Data for Large Shared Data
Banks."[10] Despite not entirely adhering to the relational model as described by Codd, it became
the most widely used database language.[11][12]
SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the
International Organization for Standardization (ISO) in 1987.[13] Since then, the standard has
been revised to include a larger set of features. Despite the existence of such standards, most
SQL code is not completely portable among different database systems without adjustments.
SQL Command
Database languages are used for read, update and store data in a database. There are several such
languages that can be used for this purpose; one of them is SQL (Structured Query Language).
A DBMS must provide appropriate languages and interfaces for each category of users to
express database queries and updates. Database Languages are used to create and maintain
database on computer. There are large numbers of database languages like Oracle, MySQL, MS
Access, dBase, FoxPro etc. SQL statements commonly used in Oracle and MS Access can be
categorized as data definition language (DDL), data control language (DCL) and data
manipulation language (DML).
All DDL commands are auto-committed. That means it saves all the changes permanently in the
database.
Command Description
create to create new table or database
alter for alteration
truncate delete data from table
drop to drop a table
rename to rename a table
These commands are to keep a check on other commands and their affect on the database. These
commands can annul(undo or invalid) changes made by other commands by rolling back to
original state. It can also make changes permanent.
Command Description
commit to permanently save
rollback to undo change
savepoint to save temporarily
Data control language provides command to grant and take back authority.
Command Description
grant grant permission of right
revoke take back permission.
Command Description
select retrieve records from one or more table
SQL Operators
Other operators have at times been suggested and/or implemented, such as the skyline operator
(for finding only those records that are not 'worse' than any others).
SQL has the case/when/then/else/end expression, which was introduced in SQL-92. In its
most general form, which is called a "searched case" in the SQL standard, it works like else if in
other programming languages:
SQL tests WHEN conditions in the order they appear in the source. If the source does not specify
an ELSE expression, SQL defaults to ELSE NULL. An abbreviated syntax—called "simple case" in
the SQL standard—mirrors switch statements:
CASE n WHEN 1
THEN 'one'
WHEN 2
THEN 'two'
ELSE 'I cannot count that high'
END
This syntax uses implicit equality comparisons, with the usual caveats for comparing with
NULL.
For the Oracle-SQL dialect, the latter can be shortened to an equivalent DECODE construct:
The last value is the default; if none is specified, it also defaults to NULL. However, unlike the
standard's "simple case", Oracle's DECODE considers two NULLs equal with each other.