• SQL入门经典数据库表DDL


    MySQL
    CREATE TABLE EMPLOYEE_TBL
    (   EMP_ID      VARCHAR(9)         NOT NULL,
        LAST_NAME   VARCHAR(15)     NOT NULL,
        FIRST_NAME  VARCHAR(15)     NOT NULL,
        MIDDLE_NAME VARCHAR(15),
        ADDRESS     VARCHAR(30)     NOT NULL,
        CITY        VARCHAR(15)     NOT NULL,
        STATE       CHAR(2)         NOT NULL,
        ZIP         INTEGER(5)      NOT NULL,
        PHONE       CHAR(10),     
        PAGER       CHAR(10),
        CONSTRAINT EMP_PK PRIMARY KEY(EMP_ID)     
    );
    
    CREATE TABLE EMPLOYEE_PAY_TBL
    (   EMP_ID      VARCHAR(9)      NOT NULL        PRIMARY KEY,
        POSITION    VARCHAR(15)     NOT NULL,
        DATE_HIRE   DATE,
        PAY_RATE    DECIMAL(4,2),
        DATE_LAST_RAISE DATE,
        SALARY      DECIMAL(8,2),
        BOUNS       DECIMAL(6,2),
        CONSTRAINT EMP_FK FOREIGN KEY(EMP_ID) REFERENCES EMPLOYEE_TBL(EMP_ID)
    );
    
    CREATE TABLE CUSTOMER_TBL
    (   CUST_ID     VARCHAR(10)     NOT NULL        PRIMARY KEY,
        CUST_NAME   VARCHAR(30)     NOT NULL,
        CUST_ADDRESS VARCHAR(20)    NOT NULL,
        CUST_CITY   VARCHAR(15)     NOT NULL,
        CUST_STATE  CHAR(2)         NOT NULL,
        CUST_ZIP    INTEGER(5)      NOT NULL,
        CUST_PHONE  CHAR(10),
        CUST_FAX    INTEGER(10)
    );
    
    CREATE TABLE ORDERS_TBL
    (   ORD_NUM        VARCHAR(10)      NOT NULL        PRIMARY KEY,
        CUST_ID         VARCHAR(10)     NOT NULL,
        PROD_ID         VARCHAR(10)     NOT NULL,
        QTY             INTEGER(6)      NOT NULL,
        ORD_DATE        DATE
    );
    
    CREATE TABLE PRODUCTS_TBL
    (   PROD_ID     VARCHAR(10)         NOT NUL         PRIMARY KEY,
        PROD_DESC   VARCHAR(40)         NOT NULL,
        COST        DECIMAL(6,2)        NOT NULL
    );
    
    
    
    Oracle and SQL Server
    CREATE TABLE EMPLOYEE_TBL
    (   EMP_ID      VARCHAR(9)      NOT NULL,
        LAST_NAME   VARCHAR(15)     NOT NULL,
        FIRST_NAME  VARCHAR(15)     NOT NULL,
        MIDDLE_NAME VARCHAR(15),
        ADDRESS     VARCHAR(30)     NOT NULL,
        CITY        VARCHAR(15)     NOT NULL,
        STATE       CHAR(2)         NOT NULL,
        ZIP         INTEGER      NOT NULL,
        PHONE       CHAR(10),     
        PAGER       CHAR(10),
        CONSTRAINT EMP_PK PRIMARY KEY(EMP_ID)     
    );
    
    CREATE TABLE EMPLOYEE_PAY_TBL
    (   EMP_ID      VARCHAR(9)      NOT NULL        PRIMARY KEY,
        POSITION    VARCHAR(15)     NOT NULL,
        DATE_HIRE   DATE,
        PAY_RATE    DECIMAL(4,2),
        DATE_LAST_RAISE DATE,
        SALARY      DECIMAL(8,2),
        BOUNS       DECIMAL(6,2),
        CONSTRAINT EMP_FK FOREIGN KEY(EMP_ID) REFERENCES EMPLOYEE_TBL(EMP_ID)
    );
    
    CREATE TABLE CUSTOMER_TBL
    (   CUST_ID     VARCHAR(10)     NOT NULL        PRIMARY KEY,
        CUST_NAME   VARCHAR(30)     NOT NULL,
        CUST_ADDRESS VARCHAR(20)    NOT NULL,
        CUST_CITY   VARCHAR(15)     NOT NULL,
        CUST_STATE  CHAR(2)         NOT NULL,
        CUST_ZIP    INTEGER      NOT NULL,
        CUST_PHONE  CHAR(10),
        CUST_FAX    VARCHAR(10)
    );
    
    CREATE TABLE ORDERS_TBL
    (   ORD_NUM        VARCHAR(10)      NOT NULL        PRIMARY KEY,
        CUST_ID         VARCHAR(10)     NOT NULL,
        PROD_ID         VARCHAR(10)     NOT NULL,
        QTY             INTEGER      NOT NULL,
        ORD_DATE        DATE
    );
    
    CREATE TABLE PRODUCTS_TBL
    (   PROD_ID     VARCHAR(10)         NOT NULL         PRIMARY KEY,
        PROD_DESC   VARCHAR(40)         NOT NULL,
        COST        DECIMAL(6,2)        NOT NULL
    );

    Oracle和MySQL中都运行了,可以正确执行。

  • 相关阅读:
    鼠标拖拽UserChromeJS脚本在线生成器
    Firefox书签转按钮UserChromeJS脚本在线生成器
    [原创]Firefox扩展
    F5和CTRL+F5的区别
    玩转log4j
    xml文件报错之Invalid byte 1 of 1byte UTF8 sequence.
    javascript 事件
    jdbc封装类(连接参数配置与web.xml)
    浅谈DHTML
    基于servlet+smartUpload的文件上传
  • 原文地址:https://www.cnblogs.com/zhangzexdu/p/5147056.html
Copyright © 2020-2023  润新知