1、創建表:用CREATE TABLE 語句,要指明:表名(不能與現有表名重復)、列名、每列的數據類型
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) );
或者:
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) );