oracle
  1. oracle-create-table

Create Table - (Oracle Tables)

In Oracle, tables are created using the CREATE TABLE statement. A table is a collection of related data stored in rows and columns. The CREATE TABLE statement specifies the name of the table, the columns it contains, and the data types of those columns.

Syntax

The syntax for creating a table in Oracle is as follows:

CREATE TABLE table_name(
    column1 datatype [constraint],
    column2 datatype [constraint],
    .....
    columnN datatype [constraint]
);

Here, table_name is the name of the table, column1, column2, ..., columnN are the names of the columns in the table, and datatype is the data type of the column. Constraints can also be added to the columns, such as NOT NULL, UNIQUE, PRIMARY KEY, etc.

Example

Here is an example of creating a table in Oracle:

CREATE TABLE employees(
    id NUMBER PRIMARY KEY,
    name VARCHAR2(50) NOT NULL,
    email VARCHAR2(50) UNIQUE,
    hire_date DATE DEFAULT SYSDATE,
    salary NUMBER(8, 2)
);

In this example, we have created a table called employees with five columns: id, name, email, hire_date, and salary. The id column is the primary key, which means that it uniquely identifies each row in the table. The name column is not null, which means that it must have a value for each row. The email column is unique, which means that each value in the column must be unique. The hire_date column has a default value of the current date, and the salary column has a data type of NUMBER(8, 2), which means that it can store up to 8 digits, with 2 digits after the decimal point.

Output

When the CREATE TABLE statement is executed, it will create a new table in the Oracle database.

Explanation

The CREATE TABLE statement creates a new table with the specified columns and data types. Constraints can also be added to the columns to ensure data integrity. In the example above, the id column is the primary key, which means that it uniquely identifies each row in the table. The name column is not null, so it must have a value for each row. The email column is unique, so each value in the column must be unique. The hire_date column has a default value of the current date, and the salary column has a data type of NUMBER(8, 2), which means that it can store up to 8 digits, with 2 digits after the decimal point.

Use

Creating tables is a fundamental part of database design and is necessary for storing and managing data in a structured way. Tables are used to represent entities in the real world and are the basis for organizing and storing data in a database.

Important Points

  • A table is a collection of related data stored in rows and columns.
  • Tables are created using the CREATE TABLE statement.
  • The CREATE TABLE statement specifies the name of the table, the columns it contains, and the data types of those columns.
  • Constraints can be added to the columns for data integrity.
  • Tables are used to represent entities in the real world and are the basis for organizing and storing data in a database.

Summary

In summary, creating tables is a fundamental part of database design and is necessary for storing and managing data in a structured way. Tables are created using the CREATE TABLE statement, which specifies the name of the table, the columns it contains, and the data types of those columns. Constraints can also be added to the columns to ensure data integrity. Tables are used to represent entities in the real world and are the basis for organizing and storing data in a database.

Published on: