To create a new table in Oracle, you can use the CREATE TABLE
statement. Here's the basic syntax:
CREATE TABLE table_name (
column1 datatype [optional_parameters] [column_constraint],
column2 datatype [optional_parameters] [column_constraint],
column3 datatype [optional_parameters] [column_constraint],
...
[table_constraint]
);
Here's an example that creates a new table named employees
:
CREATE TABLE employees (
id NUMBER(10) PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
email VARCHAR2(100),
hire_date DATE
);
This statement creates a new table named employees
with five columns: id
, first_name
, last_name
, email
, and hire_date
. The id
column is defined as a number data type with a maximum length of 10 digits and is set as the primary key using the PRIMARY KEY
constraint. The first_name
, last_name
, and email
columns are defined as variable-length character strings with maximum lengths of 50, 50, and 100 characters, respectively. The hire_date
column is defined as a date data type.
Once the table is created, you can insert data into it using the INSERT INTO
statement and query the data using the SELECT
statement.
Comments
Post a Comment