Published by : Obay Salah , November 19, 2024

Database tables are structures used to store data in the form of fields (columns) and records (rows).

  • Fields (Columns): Define the type of data to be stored (e.g., text, number, date).
  • Records (Rows): Contain actual data for each column.

In simple terms, a table is a combination of rows and columns.

SQL provides a variety of queries to interact with the data, such as creating tables, inserting, updating, or deleting records.


Creating a Table in Oracle Database:

To create a table in an Oracle database, you use the CREATE TABLE statement. Below is an example of creating an employees table:

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

Explanation of the Query:

  1. CREATE TABLE employees
  • Creates a new table named employees.
  1. employee_id NUMBER PRIMARY KEY
  • Defines a column named employee_id as a number type and sets it as the primary key (ensuring uniqueness).
  1. first_name VARCHAR2(50)
  • Defines a column named first_name to store up to 50 characters.
  1. last_name VARCHAR2(50)
  • Defines a column named last_name to store up to 50 characters.
  1. hire_date DATE
  • Defines a column named hire_date to store date values.
  1. salary NUMBER(10, 2)
  • Defines a column named salary to store numeric values, allowing up to 10 digits with 2 digits after the decimal point.


Tags : SQL

You May Also Like

Comments

no comment yet!