0009 notes 05-Table creation and constraints, SQL required notes 05-

Source: Internet
Author: User

0009 notes 05-Table creation and constraints, SQL required notes 05-

1. CREATE a TABLE: Use the create table statement to specify the TABLE name (which cannot be the same as the existing TABLE name), column name, and data type of each column.

CREATE TABLE product(    prod_id            char(10),    vend_id            char(10),    prod_name          char(254),    prod_price         number(8,2),    prod_desc          varchar(1000)  );

Create table product (prod_id char (10) not null primary key, vend_id char (10) not null, prod_name char (254) not null, prod_price number (8, 2) not null check (prod_price> 0), prod_desc varchar (1000) not null, CONSTRAINT for_vend_id foreign key (vend_id) REFERENCES vendors (vend_id ));

Or:

CREATE TABLE product(    prod_id        char(10)       NOT NULL,     vend_id        char(10)       NOT NULL,     prod_name      char(254)      NOT NULL,     prod_price     number(8,2)    NOT NULL,     prod_desc      varchar(1000)  NOT NULL,PRIMARY KEY(prod_id),CHECK(prod_price>0),CONSTRAINT for_vend_id FOREIGN KEY(vend_id) REFERENCES vendors(vend_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.