免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 862 | 回复: 0
打印 上一主题 下一主题

关系表创建始末 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:44 |只看该作者 |倒序浏览
CREATE SMALLFILE TABLESPACE "LINUXSPACE" DATAFILE '/u/app/oracle/oradata/testorcl/LINUXDATA' SIZE 100M LOGGING EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO    ----创建永久表空间和数据文件
SQL> select * from v$tablespace;
       TS# NAME                           INC BIG FLA ENC
---------- ------------------------------ --- --- --- ---
         0 SYSTEM                         YES NO  YES
         1 UNDOTBS1                       YES NO  YES
         2 SYSAUX                         YES NO  YES
         4 USERS                          YES NO  YES
         3 TEMP                           NO  NO  YES
         6 EXAMPLE                        YES NO  YES
         7 LINUXSPACE                     YES YES YES
7 rows selected.
SQL> create user oratest identified by oratest default tablespace linuxspace temporary tablespace temp;  -----创建用户给予表空间
User created.
SQL> select username,default_tablespace,temporary_tablespace from user_users;
USERNAME   DEFAULT_TABLESPACE    TEMPORARY_TABLESPACE
-------------------- ------------------------------             ------------------------------
ORATEST                 TLM52                          TEMP
SQL> grant connect,resource,dba to oratest;  -----预定义角色                                              
Grant succeeded.
SQL> connect oratest/oratest      ----login
Connected.
SQL> show user         --------show
USER is "ORATEST"
SQL>  create schema s-t authorization oratest;   ------给用户创建模式名
SQL> create table student(sno char(5) not null,   ---------创建student关系
  2  sname char(6),
  3  s*** char(2),
  4  sage varchar(4),
  5  sdept char(4),
  6  Constraint StudentPK Primary Key (Sno),
  7  Constraint SageCK Check (Sage > 0 AND Sage <150));
Table created.
SQL> create table course ( cno char(4) not null,  -----------创建课程关系
  2  cname varchar(20),
  3  cpno char(1),
  4  ccredit int default 0,
  5  constraint corusepk primary key (cno));
SQL> create table sc ( sno char(5) not null,        ------------选课关系
  2  cno char(4) not null,
  3  grade int default 0,
  4  constraint scpk primary key(sno,cno),
  5  constraint studentfk foreign key (sno) references student(sno),
  6  constraint coursefk foreign key (cno) references course(cno),
  7  Constraint GradeCK Check (Grade >= 0 AND Grade <= 100));
SQL> commit;
SQL> create table xxx as select * from student;  ------- 创建xxx
Table created.
SQL> Alter Table student Add age int constraint CheckAge check (age>0 and age<150); --------修改追加age 属性
SQL> drop table xxx;

 
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP