Published by : Obay Salah , November 19, 2024

 Database tables are used to store data in the form of some structures (fields and records). Here, a field is a column that specifies the type of data to be stored in a table and a record is a row that contains actual data. In simple words, we can say that a table is a combination of rows and columns.

SQL provides various queries to interact with data in a convenient manner. We can use SQL statements to create and delete tables and insert, update and delete data in these tables.

To create a table in an Oracle database, you can use the SQL CREATE TABLE statement. Here is a simple example that illustrates how to create a table:


CREATE TABLE employees (
    employee_id NUMBER PRIMARY KEY,
    first_name VARCHAR2(50),
    last_name VARCHAR2(50),
    hire_date DATE,
    salary NUMBER(10, 2)
);                

CREATE TABLE employees: The command starts by creating a table named "employees".

employee_id NUMBER PRIMARY KEY: Defines the column "employee_id" as a number, which is the primary key of the table.

first_name VARCHAR2(50): A column to store the first name, up to 50 characters.

last_name VARCHAR2(50): A column to store the last name, up to 50 characters.

hire_date DATE: A column to store the date of employment.


salary NUMBER(10, 2): A column to store the salary, with the ability to store 10 numbers, including two digits after the decimal point.


Tags : SQL

You May Also Like

Comments

no comment yet!