Sample Table Creation Insertion and Display Data

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;
IDDepartmentNameLocationDepartmentHead
1ITLondonRick
2PayrollDelhiRon
3HRNew YorkChristie
4Other DepartmentSydneyCindrella

 

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;
IDNameGenderSalaryDepartmentId
1TomMale40001
2PamFemale30003
3JohnMale35001
4SamMale45002
5ToddMale28002
6BenMale70001
7SaraFemale48003
8ValarieFemale55001
9JamesMale6500NULL
10RussellMale8800NULL

Related Posts