(DATABSE
ADMINISTRATION)
INTERACTIVE SQL-PART 1
MODIFYING THE STRUCTURE
OF TABLES
•The structure of the table can be modified by the using the “ALTER
TABLE” command.
•ALTER TABLE allows changing the structure of an existing table.
•It is possible to:
Output:
Table altered
MODIFYING EXISTING
COLUMN
Syntax:
(<NEW SIZE>));
Example:
ALTER TABLE CUSTOMER MODIFY (FIRSTNAME CHAR(20));
Output:
Table altered
RENAMING TABLES
The syntax to rename table is:
Example:
RENAME BUSINESS TO INCOME;
Output:
Table renamed
DELETE OPERATIONS
The DELTETE command deletes rows from the table that satisfies the
condition provided by its where clause, and returns the number of records
deleted.
If a DELETE statement without a WHERE clause is issued then, all rows are
deleted.
Example:
• DELETE FROM CUSTOMERS;
Output:
• 16 rows deleted
Removal of specific row
Synatx:
DELETE FROM <TABLE NAME> WHERE <CONDITION>;
Example:
DELETE FROM BILLS WHERE BILLDT<‘01-Aug-2000’;
Output:
2 rows deleted
USING THE BETWEEN
OPERATOR
1. In order to select data that is within a range of values, the “BETWEEN” operator is used.
2. The BETWEEN operator allows the selection of rows that contain values within a
specified lower and upper limit.
5. You can use the WHERE clause and the AND operator.
LIST THE NAME AND SALARY OF ALL THE
EMPLOYEES WITH SALARIES GREATER THAN OR
EQUAL TO $1000 AND LESS THAN OR EQUAL TO $
5,000.
ENAME SAL
---------- ---------
MARTIN 1250
TURNER 1500
WARD 1250
ADAMS 1100
MILLER 1300
USING THE IN OPERATOR
1. The IN operator helps reduce the need to use multiple OR conditions.
2. It is used to test for values in a specified list.
Example
Display employee number, name, salary, and manager’s employee number of all the employees whose manager’s
employee number is 7902, 7566, or 7788.
The SELECT statement above returns the employee name from the
EMP table for any employee whose name begins with an “S.” Note
the uppercase “S.” Names beginning with an “s” will not be
returned.
USING THE LIKE OPERATOR
You can combine pattern-matching characters.
Example:
List the employees whose name have the second character as A.
SQL> SELECT ename
2 FROM emp
3 WHEREename LIKE '_A%';
ENAME
----------
MARTIN
JAMES
WARD
USING THE IS NULL OPERATOR
1. The IS NULL operator tests for values that are null.
2. A null value means the value is unavailable, unassigned, unknown, or inapplicable.
3. Therefore, you cannot test with (=) because a null value cannot be equal or unequal to
any value.
ENAME MGR
---------- ---------
KING
The slide example retrieves the name and manager of all employees who do not
have a manager.
SORTING DATA IN A TABLE
1. Oracle allows data from a table to be viewed in a sorted order.
2. The rows retrieved from the table will be sorted in either
ascending or descending order depending on the condition
specified in the SELECT statement.
3. Sort rows with the order by clause.
<[SORT ORDER]>;
3. In the ORDER BY clause, specify the columns, and separate the column
names using commas.
4. If you want to reverse the order of a column, specify DESC after its
name.
5. You can order by columns that are not included in the SELECT clause.
EXAMPLE
2. Add a column called “TELEPHONE” of data type ‘Number’ and ‘Size’ = 10 to the
CLIENT_MASTER table.
4. List the name of all clients having ‘a’ as the second letter in their names.
5. List the clients who stay in a city whose first letter is ‘L’.
9. List the name, city and state of clients who are not in the state of ‘SINDH’.