CREATE TABLE

Creating a table is the creation of a data structure into which we can then insert data.

Structure:

 

CREATE TABLE tablename
(column_name1 data_type,
column_name2 data_type,
column_name3 data_type);

Example1:

We will create a Customer table with the following attributes:

– We will have a CUSTOMERID field with data type NUMBER. This means that we will enter numbers here.
– NAME with VARCHAR2, here we will enter text values.
– HAIR with VARCHAR2, we will insert text values.
– SALARY with NUMBER, we’ll enter numbers.

CREATE TABLE Customer
(CUSTOMERID NUMBER,
NAME VARCHAR2(100),
HAIR VARCHAR2(100),
SALARY NUMBER);

Example2:

Let’s create another table:

CREATE TABLE Colors
(COLORID NUMBER,
COLOR VARCHAR2(100));

Example3:

CREATE TABLE Friends
(FriendID NUMBER,
Friend VARCHAR2(100),
ColorID NUMBER);

Example4:

CREATE TABLE Staff
(StaffID NUMBER,
Staff_Name VARCHAR2(100),
SupervisorId NUMBER);

Example5:

We can also use an existing table to create a table. We’ll show you how to use the Customer table to create a new Mutated_Customers table.

CREATE TABLE Mutated_Customers
AS
SELECT CUSTOMERID, NAME 
FROM Customer;

Leave a Comment

Your email address will not be published. Required fields are marked *