课程表

Oracle 基础教程

Oracle 进阶教程

Oracle PL/SQL

Oracle OEM

Oracle 备份和恢复

Oracle RAC

工具箱
速查手册

Oracle SQL语句

当前位置:免费教程 » 数据库/运维 » Oracle

通过前面的讲解,我们知道SQL语句可以对Oracle进行对象创建、删除,数据的插入、删除、更新,以及数据库的管理等操作,SQL是一个结构化的的查询语言(Structured Query Language ),不仅仅适用于ORACLE数据库,再其它的数据也适用。

在 Oracle 开发中,客户端把 SQL 语句发送给服务器,服务器对 SQL 语句进行编译、执行,把执行的结果返回给客户端。常用的SQL语句大致可以分为五类:

  • 数据定义语言(DDL),包括 CREATE(创建)命令、 ALTER(修改)命令、 DROP(删除)命令等。

  • 数据操纵语言(DML),包括 INSERT(插入)命令、 UPDATE(更新)命令、 DELETE(删除)命令、 SELECT … FOR UPDATE(查询)等。

  • 数据查询语言(DQL),包括基本查询语句、 Order By 子句、 Group By 子句等。

  • 事务控制语言(TCL),包括 COMMIT(提交)命令、 SAVEPOINT(保存点)命令、ROLLBACK(回滚)命令。     

  • 数据控制语言(DCL), GRANT(授权)命令、 REVOKE(撤销)命令。

在Oracle基础教程所有案例所需的表结构的SQL执行的脚本语句如下:

  1. -- Create table
  2. create table STUINFO
  3. (
  4.   stuid      VARCHAR2(11) not null,
  5.   stuname    VARCHAR2(50) not null,
  6.   sex        CHAR(1) not null,
  7.   age        NUMBER(2) not null,
  8.   classno    VARCHAR2(7) not null,
  9.   stuaddress VARCHAR2(100) default '地址未录入',
  10.   grade      CHAR(4) not null,
  11.   enroldate  DATE,
  12.   idnumber   VARCHAR2(18) default '身份证未采集' not null
  13. )
  14. tablespace USERS
  15.   pctfree 10
  16.   initrans 1
  17.   maxtrans 255
  18.   storage
  19.   (
  20.     initial 64K
  21.     next 1M
  22.     minextents 1
  23.     maxextents unlimited
  24.   );
  25. -- Add comments to the table 
  26. comment on table STUINFO
  27.   is '学生信息表';
  28. -- Add comments to the columns 
  29. comment on column STUINFO.stuid
  30.   is '学号';
  31. comment on column STUINFO.stuname
  32.   is '学生姓名';
  33. comment on column STUINFO.sex
  34.   is '学生性别';
  35. comment on column STUINFO.age
  36.   is '学生年龄';
  37. comment on column STUINFO.classno
  38.   is '学生班级号';
  39. comment on column STUINFO.stuaddress
  40.   is '学生住址';
  41. comment on column STUINFO.grade
  42.   is '年级';
  43. comment on column STUINFO.enroldate
  44.   is '入学时间';
  45. comment on column STUINFO.idnumber
  46.   is '身份证号';
  47. -- Create/Recreate primary, unique and foreign key constraints 
  48. alter table STUINFO
  49.   add constraint PK_STUINFO primary key (STUID)
  50.   using index 
  51.   tablespace USERS
  52.   pctfree 10
  53.   initrans 2
  54.   maxtrans 255
  55.   storage
  56.   (
  57.     initial 64K
  58.     next 1M
  59.     minextents 1
  60.     maxextents unlimited
  61.   );
  62.    
  63.   -- Create table
  64. create table CLASS
  65. (
  66.   classno        VARCHAR2(7) not null,
  67.   classname      VARCHAR2(50),
  68.   monitorid      VARCHAR2(11),
  69.   monitorname    VARCHAR2(50),
  70.   headmasterid   VARCHAR2(8),
  71.   headmastername VARCHAR2(50),
  72.   classaddress   VARCHAR2(50),
  73.   enterdate      DATE
  74. )
  75. tablespace USERS
  76.   pctfree 10
  77.   initrans 1
  78.   maxtrans 255
  79.   storage
  80.   (
  81.     initial 64K
  82.     minextents 1
  83.     maxextents unlimited
  84.   );
  85. -- Add comments to the table 
  86. comment on table CLASS
  87.   is '班级信息表';
  88. -- Add comments to the columns 
  89. comment on column CLASS.classno
  90.   is '班级号';
  91. comment on column CLASS.classname
  92.   is '班级名称';
  93. comment on column CLASS.monitorid
  94.   is '班长学号';
  95. comment on column CLASS.monitorname
  96.   is '班长姓名';
  97. comment on column CLASS.headmasterid
  98.   is '班主任教师号';
  99. comment on column CLASS.headmastername
  100.   is '班主任姓名';
  101. comment on column CLASS.classaddress
  102.   is '班级地址';
  103. comment on column CLASS.enterdate
  104.   is '录入时间';
  105. -- Create/Recreate primary, unique and foreign key constraints 
  106. alter table CLASS
  107.   add constraint PK_CLASS primary key (CLASSNO)
  108.   using index 
  109.   tablespace USERS
  110.   pctfree 10
  111.   initrans 2
  112.   maxtrans 255;
  113.  
  114.  
  115. -- Create table
  116. create table COURSE
  117. (
  118.   courseid   VARCHAR2(9) not null,
  119.   schyear    VARCHAR2(4),
  120.   term       VARCHAR2(4),
  121.   coursename VARCHAR2(100)
  122. )
  123. tablespace USERS
  124.   pctfree 10
  125.   initrans 1
  126.   maxtrans 255
  127.   storage
  128.   (
  129.     initial 64K
  130.     next 1M
  131.     minextents 1
  132.     maxextents unlimited
  133.   );
  134. -- Add comments to the table 
  135. comment on table COURSE
  136.   is '课程表';
  137. -- Add comments to the columns 
  138. comment on column COURSE.courseid
  139.   is '课程id';
  140. comment on column COURSE.schyear
  141.   is '学年';
  142. comment on column COURSE.term
  143.   is '学期';
  144. comment on column COURSE.coursename
  145.   is '课程名称';
  146. -- Create/Recreate primary, unique and foreign key constraints 
  147. alter table COURSE
  148.   add constraint PK_COURSE primary key (COURSEID)
  149.   using index 
  150.   tablespace USERS
  151.   pctfree 10
  152.   initrans 2
  153.   maxtrans 255
  154.   storage
  155.   (
  156.     initial 64K
  157.     next 1M
  158.     minextents 1
  159.     maxextents unlimited
  160.   );
  161.    
  162.   -- Create table
  163. create table STUCOURSE
  164. (
  165.   selectid   VARCHAR2(18) not null,
  166.   stuid      VARCHAR2(11),
  167.   courseid   VARCHAR2(9),
  168.   schyear    VARCHAR2(4),
  169.   term       VARCHAR2(4),
  170.   redo       VARCHAR2(1),
  171.   selectdate DATE
  172. )
  173. tablespace USERS
  174.   pctfree 10
  175.   initrans 1
  176.   maxtrans 255
  177.   storage
  178.   (
  179.     initial 64K
  180.     minextents 1
  181.     maxextents unlimited
  182.   );
  183. -- Add comments to the table 
  184. comment on table STUCOURSE
  185.   is '学生选课表';
  186. -- Add comments to the columns 
  187. comment on column STUCOURSE.selectid
  188.   is '选课id';
  189. comment on column STUCOURSE.stuid
  190.   is '学号';
  191. comment on column STUCOURSE.courseid
  192.   is '课程id';
  193. comment on column STUCOURSE.schyear
  194.   is '年度';
  195. comment on column STUCOURSE.term
  196.   is '学期';
  197. comment on column STUCOURSE.redo
  198.   is '是否重修';
  199. comment on column STUCOURSE.selectdate
  200.   is '选课时间';
  201. -- Create/Recreate primary, unique and foreign key constraints 
  202. alter table STUCOURSE
  203.   add constraint PK_STUCOURSE primary key (SELECTID)
  204.   using index 
  205.   tablespace USERS
  206.   pctfree 10
  207.   initrans 2
  208.   maxtrans 255;
  209.  
  210.  
  211. -- Create table
  212. create table SCORE
  213. (
  214.   scoreid  VARCHAR2(18) not null,
  215.   stuid    VARCHAR2(11),
  216.   courseid VARCHAR2(9),
  217.   score    NUMBER,
  218.   scdate   DATE
  219. )
  220. tablespace USERS
  221.   pctfree 10
  222.   initrans 1
  223.   maxtrans 255
  224.   storage
  225.   (
  226.     initial 64K
  227.     next 1M
  228.     minextents 1
  229.     maxextents unlimited
  230.   );
  231. -- Add comments to the table 
  232. comment on table SCORE
  233.   is '学生成绩表';
  234. -- Add comments to the columns 
  235. comment on column SCORE.scoreid
  236.   is '学生成绩id';
  237. comment on column SCORE.stuid
  238.   is '学生学号';
  239. comment on column SCORE.courseid
  240.   is '课程id(年度+上下学期+课程序列)';
  241. comment on column SCORE.score
  242.   is '成绩';
  243. comment on column SCORE.scdate
  244.   is '成绩录入时间';
  245. -- Create/Recreate primary, unique and foreign key constraints 
  246. alter table SCORE
  247.   add constraint PK_SCORE primary key (SCOREID)
  248.   using index 
  249.   tablespace USERS
  250.   pctfree 10
  251.   initrans 2
  252.   maxtrans 255
  253.   storage
  254.   (
  255.     initial 64K
  256.     next 1M
  257.     minextents 1
  258.     maxextents unlimited
  259.   );


转载本站内容时,请务必注明来自W3xue,违者必究。
 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号