April 15th, 2009
Table Creation, Introduction (Part 2 of 2)
Posted by
admin in
P. Table Creation
Here is a sample CREATE TABLE statement.
CREATE TABLE PAYROLL_TBL
(EMPL_ID CHAR(4) NOT NULL,
STOR_ID CHAR(4) NOT NULL,
DUE_DATE DATE NOT NULL,
HRSTHIS_PAYPRD DECIMAL(4,1) NOT NULL DEFAULT,
GROSS DECIMAL(8,2) NOT NULL DEFAULT,
TAX DECIMAL(8,2) NOT NULL DEFAULT,
CONSTRAINT PAYROLL_PK PRIMARY KEY (EMPL_ID, STOR_ID, DUE_DATE),
CONSTRAINT PYRL_EMPL_FK FOREIGN KEY (EMPL_ID)
REFERENCES EMPLOYEE_TBL(EMPL_ID),
CONSTRAINT PYRL_STOR_FK FOREIGN KEY (STOR_ID)
REFERENCES STORE_TBL(STOR_ID));
As you can see, it contains a table name with many columns.
Each column has a column name, a data type, and several column constraints.
The column constraints include NOT NULL and DEFAULT.
Several named table constraints are followed by one PRIMARY KEY and two FOREIGN KEYs.
Comments Off