Table in Oracle Dtabase
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:
CREATE TABLE employees
- Creates a new table named
employees
.
employee_id NUMBER PRIMARY KEY
- Defines a column named
employee_id
as a number type and sets it as the primary key (ensuring uniqueness).
first_name VARCHAR2(50)
- Defines a column named
first_name
to store up to 50 characters.
last_name VARCHAR2(50)
- Defines a column named
last_name
to store up to 50 characters.
hire_date DATE
- Defines a column named
hire_date
to store date values.
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.
Comments
no comment yet!