數據加載中……
          Oracle創建數據表空間,用戶,授權,表,索引,簇(2008-07-26 22:38:59)

          //創建臨時表空間(日志文件)
          create temporary tablespace test_temp
          tempfile 'E:\oracle\test_temp01.dbf'
          size 32m
          autoextend on
          next 32m maxsize 2048m
          extent management local;

          //創建數據表空間
          create tablespace test_data
          logging
          datafile 'E:\oracle\test_data01.dbf'
          size 32m
          autoextend on
          next 32m maxsize 2048m
          extent management local;

          //創建用戶并指定表空間
          create user 用戶名 identified by 密碼
          default tablespace test_data
          temporary tablespace test_temp;

          //給用戶授予權限

          grant connect,resource to 用戶名

          ————————————————————————————————————

          create cluster s_t_cluster(tid number(8));--創建索引簇
          ----------------------------------------------------1
          --建立簇表stu
          create table stu(
                 tid number(8),
                 sname varchar2(50),
                 sinfo varchar2(50),
                 constraint pk_tid primary key(tid)
          )cluster s_t_cluster(tid)
          --建立簇表sc
          create table sc(
                 tid number(8),
                 score number(8),
                 constraint fk_tid foreign key(tid) references stu(tid)
          )cluster s_t_cluster(tid)
          ------------------------------------------------------2
          --建立簇索引
          create index s_t_idx on cluster s_t_cluster;
          ------------------------------------------------------3
          --插入數據
          insert into stu(tid,sname,sinfo)values(1,'haha','usa');
          insert into stu(tid,sname,sinfo)values(2,'gaga','Japan');
          insert into sc values(1,90);
          insert into sc values(2,85);
          --查詢
          select s.sname,s.sinfo,i.score from stu s,sc i where s.tid=i.tid
          --建立序列
          create sequence stu_SEQ
          minvalue 1
          maxvalue 99999999
          start with 3
          increment by 1
          cache 20;

          --用命令插入N條數據往表stu
          declare
          x number;
          begin
            for x in 1..100000 loop
              insert into stu values(stu_seq.nextval,'名字'||x,'地址'||x);
            end loop;
          end;
          ---------------------------------------------
          --用命令插入N條數據往表sc
          declare
          x number;
          begin
            for x in 1..10000 loop
              insert into sc values(sc_seq.nextval,x+50);
            end loop;
          end;
          ---------------------------------------------
          --查詢
          select s.sname,s.sinfo,i.score from stu s,sc i where s.tid=i.tid--未加索引時的普通查詢太慢了
          --使用索引簇查詢
          select s.sname,s.sinfo,i.score from stu s,sc i where s.tid=i.tid

          ————————————————————————————————————————

          //創建表,序列號(sequence)

          create table test1(
                 tid number(8),
                 tname varchar2(50),
                 tbd date,
                 constraint pk_tid primary key(tid)
          )
          select * from test1
          ==============================================================
          create sequence test1Seq --自定義的序列名
          increment by 1           --每次加幾個,即遞增的間隔
          start with 1             --從1開始計數
          nomaxvalue               --不設置最大值
          nocycle                  --一直累加,不循環
          cache 10;
          ==============================================================
          insert into test1(tid,tname,tbd)values(test1Seq.Nextval,'ccc',sysdate);

          posted on 2009-03-19 20:13 flyleer 閱讀(909) 評論(0)  編輯  收藏

          主站蜘蛛池模板: 垫江县| 杭锦旗| 治多县| 安远县| 洪湖市| 古丈县| 西华县| 惠来县| 万源市| 青海省| 青田县| 抚顺县| 仁化县| 鞍山市| 和静县| 鄢陵县| 阜康市| 比如县| 阿拉善右旗| 南汇区| 乌鲁木齐市| 沂水县| 新巴尔虎左旗| 芷江| 东乌珠穆沁旗| 钦州市| 葵青区| 遵化市| 宝山区| 石台县| 德州市| 德阳市| 玉龙| 伊吾县| 长武县| 扶绥县| 汝阳县| 额济纳旗| 合作市| 罗田县| 泽州县|