官术网_书友最值得收藏!

2.7 創(chuàng)建數(shù)據(jù)表并生成樣本數(shù)據(jù)

設(shè)計好對象后,就可以開始創(chuàng)建數(shù)據(jù)表了,創(chuàng)建數(shù)據(jù)表的SQL語句介紹如下。

(1)本地數(shù)據(jù)庫Derby數(shù)據(jù)表的代碼如下。

        # 創(chuàng)建用戶users數(shù)據(jù)表
        CREATE TABLE USERS (
          ID INT GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1),
          USERNAME VARCHAR(8) NOT NULL,
          PASSWORD VARCHAR(8) NOT NULL,
          USERTAG CHAR(1) WITH DEFAULT '0',
          PRIMARY KEY(ID) );
        # 創(chuàng)建教學單位名稱teachunit數(shù)據(jù)表
        CREATE TABLE teachunit (
          id int generated always as identity(start with 1,increment by 1),
          unitid char(8) not null,
          unitname varchar(8) not null,
          primary key(id));
        # 創(chuàng)建年度教學單位yearteachunit數(shù)據(jù)表
        CREATE TABLE yearteachunit (
          id int generated always as identity(start with 1,increment by 1),
          nian int not null,
          unitid char(2) not null,
          haszyk char(1) not null with default '1',
          hasggk char(1) not null with default '0',
          ssb int not null with default 0,
          jfys decimal(10,2) not null with default 0,
          jfss decimal(10,2) not null with default 0,
          jxywper decimal(6,2) not null with default 0,
          jxglper decimal(6,2) not null with default 0,
          jxyjper decimal(6,2) not null with default 0,
          szpyper decimal(6,2) not null with default 0,
          ta1 int not null with default 0,
          ta2 int not null with default 0,
          ta3 int not null with default 0,
          ta4 int not null with default 0,
          ta5 int not null with default 0,
          ta6 int not null with default 0,
          ta7 int not null with default 0,
          ta8 int not null with default 0,
          primary key(id));
        # 創(chuàng)建年度測算結(jié)果calcresult數(shù)據(jù)表
        CREATE TABLE calcresult (
          id int generated always as identity(start with 1,increment by 1),
          nian int not null,
          unitid char(2) not null,
          ui decimal(10,2) not null with default 0,
          pi decimal(10,2) not null with default 0,
          ci decimal(10,2) not null with default 0,
          ryjf decimal(10,2) not null with default 0,
          zhywf decimal(10,2) not null with default 0,
          primary key(id));
        # 創(chuàng)建教學單位課程明細course數(shù)據(jù)表
        CREATE TABLE course (
          id int generated always as identity(start with 1,increment by 1),
          nian int not null,
          term char(1) not null,
          unitid char(2) not null,
          courseid char(8) not null,
          coursename char(40) not null,
          coursetype char(1) not null,
          classname char(40) not null,
          nj int not null with default 0,
          n2j int not null with default 0,
          r1j decimal(3,1) not null with default 1.0,
          r2j decimal(3,1) not null with default 1.0,
          r3j decimal(3,1) not null with default 1.0,
          primary key(id));
        # 創(chuàng)建公共參數(shù)pubdata數(shù)據(jù)表
        CREATE TABLE pubdata (
          id int generated always as identity(start with 1,increment by 1),
          nian int not null,
          mt decimal(8,2) not null with default 0,
          rte decimal(10,5) not null with default 0,
          mte decimal(10,5) not null with default 0,
          sjf decimal(6,2) not null with default 0,
          uper decimal(5,2) not null with default 0,
          pper decimal(5,2) not null with default 0,
          cper decimal(5,2) not null with default 0,
          jcjper decimal(5,2) not null with default 0,
          xsknbzper decimal(5,2) not null with default 0,
          xshdjfper decimal(5,2) not null with default 0,
          xsjxjper decimal(5,2) not null with default 0,
          tb1 decimal(4,2) not null with default 1.0,
          tb2 decimal(4,2) not null with default 1.0,
          tb3 decimal(4,2) not null with default 1.0,
          tb4 decimal(4,2) not null with default 1.0,
          tb5 decimal(4,2) not null with default 1.0,
          tb6 decimal(4,2) not null with default 1.0,
          tb7 decimal(4,2) not null with default 1.0,
          tb8 decimal(4,2) not null with default 1.0,
          primary key(id));

(2)遠程教學單位數(shù)據(jù)庫服務器數(shù)據(jù)表的代碼如下所示。

        # 創(chuàng)建MySQL數(shù)據(jù)庫課程信息courseinfo數(shù)據(jù)表
        DROP DATABASE IF EXISTS `jwgl`;
        CREATE DATABASE `jwgl`;
        USE `jwgl`;
        CREATE TABLE `courseinfo` (
          `id` int(11) NOT NULL auto_increment,
          `nian` int(4) NOT NULL,
          `term` char(1) NOT NULL,
          `unitid` char(2) NOT NULL,
          `courseid` char(8) NOT NULL,
          `coursename` char(40) NOT NULL,
          `coursetype` char(1) NOT NULL,
          `classname` char(40) NOT NULL,
          `nj` int(6) NOT NULL default '0',
          `n2j` int(4) NOT NULL default '0',
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED COMMENT='課程明細表';

(3)生成樣本數(shù)據(jù)

下面是生成樣本數(shù)據(jù)的一些示例SQL語句,隨書所附光盤中有更詳細的樣本SQL語句。

        # 生成Derby的users表數(shù)據(jù)
        insert into USERS(USERNAME,PASSWORD,USERTAG) values('admin','1010','2');
        insert into USERS(USERNAME,PASSWORD,USERTAG) values('jwc','jwc','1');
        # 生成Derby的teachunit表數(shù)據(jù)
        insert into teachunit(unitid,unitname) values('01','英語');
        insert into teachunit(unitid,unitname) values('02','機電學院');
        # 生成Derby的yearteachunit表數(shù)據(jù)
        insert into yearteachunit(nian,unitid,hasggk,ssb,jfys,jfss,ta1,ta3,ta6)
            values(2006,'01','1',16,535500.0,535500.0,5,8,15);
        insert into yearteachunit(nian,unitid,hasggk,ssb,jfys,jfss,ta1,ta3,ta6)
            values(2006,'02','0',17,635500.0,535500.0,6,12,10);
        # 生成Derby的calcresult表數(shù)據(jù)
        insert into calcresult(nian,unitid,ui,pi,ci,ryjf,zhywf)
            values(2006,'01',56,66,43,50,95);
        insert into calcresult(nian,unitid,ui,pi,ci,ryjf,zhywf)
            values(2006,'02',46,66,63,55,78);
        # 生成Derby的course表數(shù)據(jù)
        insert into course(nian,term,unitid,courseid,coursename,coursetype,classname,
            nj,n2j) values(2006,'1','01','01100010','大學英語','1','科技英語041-2',78,60);
        insert into course(nian,term,unitid,courseid,coursename,coursetype,classname,
            nj,n2j) values(2006,'1','01','01100120','高級英語','1','英語031-2',65,60);
        # 生成Derby的pubdata表數(shù)據(jù)
         insert into pubdata(nian,tb1,tb2,tb3,tb4,tb5,tb6,tb7,tb8)
            values(2006,1.3,1.25,1.2,1.15,1.1,1.05,1.0,0.9);
         insert into pubdata(nian,tb1,tb2,tb3,tb4,tb5,tb6,tb7,tb8)
            values(2007,1.3,1.25,1.2,1.15,1.1,1.05,1.0,0.9);
        # 生成MySQL的courseinfo表數(shù)據(jù)
        INSERT INTO `courseinfo` VALUES (1,2007,'1','01','01100010','大學英語','1',
                                        '科技英語051-2',70,60);
        INSERT INTO `courseinfo` VALUES (2,2007,'1','01','01100120','高級英語','1',
                                        '英語041-2',67,60);
主站蜘蛛池模板: 嘉义市| 丰镇市| 资兴市| 巩留县| 灵台县| 宿松县| 渭南市| 汨罗市| 宜丰县| 徐州市| 赤水市| 桑植县| 子洲县| 信宜市| 顺平县| 广宁县| 天津市| 山东省| 潞城市| 康乐县| 车险| 武鸣县| 广河县| 疏附县| 博客| 依安县| 眉山市| 平塘县| 宣武区| 平湖市| 岳阳县| 龙泉市| 克什克腾旗| 文山县| 许昌市| 如皋市| 哈尔滨市| 射洪县| 惠安县| 屏东市| 巴东县|