Professional Documents
Culture Documents
Introduction to SQL
Outline
What is sql
SQL Data Manipulation Language (DML)
SQL Data Definition Language (DDL)
Aggregate function
What is SQL?
SQL stands for Structured Query Language
SQL allows you to access a database
SQL can execute queries against a database
SQL is easy to learn
SQL is an ANSI (American National Standards Institute)
standard computer language for accessing and
manipulating database systems. SQL statements are
used to insert, retrieve and update data in a database
and, delete records from a database.
SQL works with database programs like MS Access,
DB2, Informix, MS SQL Server, Oracle, Sybase, etc.
SQL Data Manipulation Language
(DML)
The query select is used to retrieve the data from the table or
database:
The result is stored in a result table, called the result-set.
SQL SELECT Syntax
– SELECT column_name(s) FROM table_name
or
– SELECT * FROM table_name: which is used for retrieve all record
of the table
Keep in Mind That...
SQL is not case sensitive
… An SQL SELECT Example
Now we want to select all the columns from the “EMPLOYEE" table.
We use the following SELECT statement:
SELECT * FROM EMPLOYEE
Tip: The asterisk (*) is a quick way of selecting all columns!
SQL WHERE Clause
Operator Description
= Equal
<> Not equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
BETWEEN Between an inclusive range
This is correct:
– SELECT * FROM student WHERE st_name ='Tove'
This is wrong:
– SELECT * FROM student WHERE st_name= aman
This is correct:
– SELECT * FROM student WHERE age>20
This is wrong:
– SELECT * FROM student WHERE age>‘20’
LIKE Condition
Student table
Modifying a Column
– Change the size of a column
– Change the precision of a numeric column
– Change the data type of a column
– Change the default value of a column
– Affects only subsequent insertion to the table
Syntax:
ALTER TABLE table_name MODIFY (column new(data type) );
Eg: ALTER TABLE Student MODIFY (first_name VARCHAR2(15));
ALTER TABLE Student MODIFY (major CHAR(3) );
…cont.
Orders table:
Company OrderNumber
– result order table: ABC Shop 5678
Sega 3412
W3Schools 6798
To display the companies in reverse alphabetical order:
SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC
Company OrderNumber
W3Schools 6798
W3Schools 2312
Sega 3412
ABC Shop 5678
Questions
Create a database called finance that consists payroll table. The payroll table looks
like this, after you create the database and the table (2 pt) answer the following
questions.