Sample Table Creation Insertion and Display Data – Learn how to create tables, insert data into tables and display data with the following examples.
Sample Table Creation Insertion and Display Data
Department_TBL1Table Creation
Here is the example for creating a Department_TBL1 table.
Note:
we are using below mentioned tables as reference tables for concepts like Foreign Key constraints, Cursors,..
CREATE TABLE Department_TBL1
(
ID INT PRIMARY KEY,
Dept_Name VARCHAR2(50),
Dept_Location VARCHAR2(50),
Dept_Head VARCHAR2(50)
);
Data Insertion
Insert into Department_TBL1 values (1, 'IT', 'London', 'Rick');
Insert into Department_TBL1 values (2, 'Payroll', 'Delhi', 'Ron');
Insert into Department_TBL1 values (3, 'HR', 'New York', 'Christie');
Insert into Department_TBL1 values (4, 'Other Department', 'Sydney', 'Cindrella');
Display Department_TBL1 Data
To display data from Department_TBL1 use following select query
SELECT * FROM Department_TBL1;
ID | DepartmentName | Location | DepartmentHead |
---|---|---|---|
1 | IT | London | Rick |
2 | Payroll | Delhi | Ron |
3 | HR | New York | Christie |
4 | Other Department | Sydney | Cindrella |
EMPLOYEE_TBL1 Table Creation
CREATE TABLE EMPLOYEE_TBL1
(
ID INT PRIMARY KEY,
NAME VARCHAR2(50),
GENDER VARCHAR2(50),
SALARY INT,
DEPARTMENTID INT,
CONSTRAINT fk_department FOREIGN KEY(DEPARTMENTID) REFERENCES DEPARTMENT_TBL1(ID)
);
Data Insertion
Insert into EMPLOYEE_TBL1 values (1, 'Tom', 'Male', 4000, 1);
Insert into EMPLOYEE_TBL1 values (2, 'Pam', 'Female', 3000, 3);
Insert into EMPLOYEE_TBL1 values (3, 'John', 'Male', 3500, 1);
Insert into EMPLOYEE_TBL1 values (4, 'Sam', 'Male', 4500, 2);
Insert into EMPLOYEE_TBL1 values (5, 'Todd', 'Male', 2800, 2);
Insert into EMPLOYEE_TBL1 values (6, 'Ben', 'Male', 7000, 1);
Insert into EMPLOYEE_TBL1 values (7, 'Sara', 'Female', 4800, 3);
Insert into EMPLOYEE_TBL1 values (8, 'Valarie', 'Female', 5500, 1);
Insert into EMPLOYEE_TBL1 values (9, 'James', 'Male', 6500, NULL);
Insert into EMPLOYEE_TBL1 values (10, 'Russell', 'Male', 8800, NULL);
Display EMPLOYEE_TBL1 Data
To display data from EMPLOYEE_TBL1 use following select query
SELECT * FROM EMPLOYEE_TBL1;
ID | Name | Gender | Salary | DepartmentId |
---|---|---|---|---|
1 | Tom | Male | 4000 | 1 |
2 | Pam | Female | 3000 | 3 |
3 | John | Male | 3500 | 1 |
4 | Sam | Male | 4500 | 2 |
5 | Todd | Male | 2800 | 2 |
6 | Ben | Male | 7000 | 1 |
7 | Sara | Female | 4800 | 3 |
8 | Valarie | Female | 5500 | 1 |
9 | James | Male | 6500 | NULL |
10 | Russell | Male | 8800 | NULL |