Intro To SQL
Intro To SQL
Intro To SQL
• character-string
• CHAR(N) (or CHARACTER(N)) is a fixed-length character string. Maximum characters
supported 255
• VARCHAR(N) (or CHAR VARYING(N), or CHARACTER VARYING(N)) is a variable-length
character string with at most N characters.
• number
• Both fixed and floating point
Constraints in SQL
• NOT NULL - Ensures that a column cannot have a NULL value
• INDEX - Use to create and retrieve data from the database very quickly
Create TABLE
Syntax
The PRIMARY KEY constraint uniquely identifies each record in a database table.
Primary keys must contain UNIQUE values, and cannot contain NULL values.
To insert a row into a table, it is necessary to have a value for each attribute,
and order matters.
SELECT *
FROM employee;
•The asterisk (*) tells Oracle to select (display) all columns contained in the
table “employee”.
THE DISTINCT CLAUSE
• Oracle provides a means for eliminating duplicate rows in a result table
through use of the DISTINCT keyword .
SELECT emp_salary
FROM employee;
EMP_SALARY
-----------------
$55,000.00
$43,000.00
$43,000.00
$25,000.00
$25,000.00
$30,000.00
$38,000.00
$25,000.00
8 rows selected.
• The query is rewritten using the DISTINCT keyword to eliminate
duplicate rows.
SELECT DISTINCT emp_salary
FROM employee;
EMP_SALARY
-------------------
$25,000.00
$30,000.00
$38,000.00
$43,000.00
$55,000.00
THE WHERE CLAUSE
= equal to
< less than
> greater than
>= greater than or equal to
<= less than or equal to
!= not equal to
<> not equal to
!> not greater than
!< not less than
Comparing Character Data
Aggregate Functions