Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Contents
Data Definition Language........................................................................................... 1
Constraints................................................................................................................. 2
Data Manipulation Language...................................................................................... 3
Retrieving Data from database................................................................................... 3
Views.......................................................................................................................... 4
Single row functions and group functions...................................................................4
2. Create a table DEPARTMENTS with the following columns and data types:
DEPARTMENT_IDNUMBERPRIMARYKEY,
DEPARTMENT_NAMEVARCHAR2(30BYTE)NOTNULL,
LOCATION_IDNUMBER
3. Create a table EMPLOYEES with the following columns and data types:
EMPLOYEE_IDNUMBERPRIMARYKEY,
FIRST_NAMEVARCHAR2(20BYTE),
LAST_NAMEVARCHAR2(25BYTE)NOTNULL,
EMAILVARCHAR2(25BYTE)NOTNULL,
PHONE_NUMBERVARCHAR2(20BYTE),
HIRE_DATEDATENOTNULL,
JOB_IDVARCHAR2(10BYTE)NOTNULL,
SALARYNUMBER(8,2),
COMMISSION_PCTNUMBER(2,2),
MANAGER_IDNUMBER,
DEPARTMENT_IDNUMBER
Constraints
1. Create the relations between the tables by alter the tables and add the FOREIGN
KEYS:
FK_EMPLOYEES_DEPARTMENTS
FK_EMPLOYEES_JOBS
FK_EMPLOYEES_EMPL_MANAGER
[OPTIONAL-HOMEWORK] FK_DEPARTMENTS_LOCATIONS
SYNTAX:
ALTER TABLE <TABLE1> ADD FOREIGN KEY (<FIELD_TABLE1>)
REFERENCES <TABLE2> (<FIELD_TABLE2>)
VALUES(TAB_EMPLOYEES_SEQ.nextval,
'Steven',
'King',
'SKING',
'515.123.4567',
sysdate,
'AD_PRES',
24000,
NULL,
NULL,
90);
Views
8. Creating a View with employees, department_name
CREATEVIEWEMPLOYEE_LISTAS
SELECTEMP.EMPLOYEE_ID,EMP.FIRST_NAME,DEPT.DEPARTMENT_NAME
FROMemployeesemp,departmentsdept
WHEREEMP.DEPARTMENT_ID=DEPT.DEPARTMENT_ID
4. Return all employees First Name, with Upper case and Email with Lower case
5. Return all employees First Name with the prefix First Name: (use concat
function). After this, do the same using || operator
6.
7.
8.
9.