SqlCREATETABLE table creation statement

Source: Internet
Author: User
The CREATETABLE statement allows you to create and define a table. This is the first step in database creation. Let's take a look at the detailed instance.

The create table statement allows you to CREATE and define a TABLE. This is the first step in database creation. Let's take a look at the detailed instances.

The basic syntax of the create table statement is:

The Code is as follows:
Create table table_name
(Column1 datatype null/not null,
Column2 datatype null/not null,
...
);

Each column must have a data type. The column should be defined as "null" or "not null". If this value is null, the default value is "null ".

Instance

The Code is as follows:

Create table suppliers
(Supplier_id number (10) not null,
Supplier_name varchar2 (50) not null,
Contact_name varchar2 (50)
);

Exercise 1:

Create a customer table to store the customer ID, name, and address information. The customer ID should be the primary key of the table.

Solution:

The create table statement for the user TABLE is:

The Code is as follows:

Create table MERs
(Customer_id number (10) not null,
Customer_name varchar2 (50) not null,
Address varchar2 (50 ),
City varchar2 (50 ),
State varchar2 (25 ),
Zip_code varchar2 (10 ),
CONSTRAINT customers_pk primary key (customer_id)
);


Exercise #2:

Create an employee table store employee ID, employee name, department, and salary information based on the department table. The primary key of the Employees table should be the number of Employees. Create a Department employee table in the DEPARTMENT_ID field of a foreign key reference table.

The Code is as follows:

Create table orders ments
(Department_id number (10) not null,
Department_name varchar2 (50) not null,
CONSTRAINT departments_pk primary key (department_id)
);

The create table statement for the employees table is:

The Code is as follows:

Create table employees
(Employee_number number (10) not null,
Employee_name varchar2 (50) not null,
Department_id number (10 ),
Salary number (6 ),
CONSTRAINT employees_pk primary key (employee_number ),
CONSTRAINT fk_ments ments
Foreign key (department_id)
REFERENCES parameters (department_id)
);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.