To create a simple table in Oracle SQL, we can use the CREATE TABLE statement. The basic syntax for the CREATE TABLE statement is as follows:
CREATE TABLE table_name (
column1 datatype,
column2 datatype,
...
);
Each column is defined with a data type and we can also specify any constraints on the column, such as NOT NULL, UNIQUE, or PRIMARY KEY. Here is an example of a simple table creation:
CREATE TABLE employees (
employee_id NUMBER(5) PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
email VARCHAR2(100) UNIQUE,
hire_date DATE,
job_title VARCHAR2(50),
salary NUMBER(10,2)
);
In this example, we created a table called "employees" with six columns: employee_id, first_name, last_name, email, hire_date, job_title, and salary.
The employee_id column is defined with the NUMBER data type and is also defined as the primary key of the table. The first_name, last_name, and job_title columns are defined as VARCHAR2 data type with a maximum length of 50 characters. The email column is also defined as a VARCHAR2 data type but has the UNIQUE constraint, meaning that each value in this column must be unique. The hire_date column is defined with the DATE data type, while the salary column is defined as a NUMBER data type with a maximum of 10 digits, including 2 decimal places.
By executing this SQL statement, the employees table will be created in the Oracle database ready to store data. We can then insert rows of data into the table using the INSERT INTO statement, or we can modify it using the ALTER or DROP commands.