Oracle
1 --创建表空间 2 create tablespace test_tablespace 3 datafile 'D:\oracle\product\10.1.0\oradata\ORCL\TEST.DBF' 4 size 100M; 5 --可选 6 autoextend on next 32M maxsize unlimited--每次扩展32 无最大限制 7 logging--日志记录 8 extent management local--表空间中盘区管理采用本地化管理方式 9 segment space management auto;--表空间中段的管理方式为自动管理方式 10 11 drop tablespace test_tablespace; 12 13 --创建用户 14 create user user_admin 15 identified by sa 16 default tablespace test_tablespace --默认表空间 17 temporary tablespace test_tablespace --临时表空间 18 19 drop user user_admin; 20 21 --授权 22 grant connect, resource to user_admin--把connect, resource 授予 epet 23 revoke resource from user_admin--撤销epet的resource角色 24 25 grant select on master to system--允许epet查看表 emp 26 grant update on emp to user_admin--允许epet更新表 emp 27 28 --创建表 29 create table pet_master 30 ( 31 id number(11,0) primary key, 32 loginid nvarchar2(50) not null, 33 password nvarchar2(20) not null, 34 status char(1) default 1 not null 35 ) 36 37 create table pet_type 38 ( 39 id number(11) not null, 40 name nvarchar2(50) not null, 41 status char(1) default 1 not null 42 ); 43 alter table pet_type add constraint pet_type primary key(id) 44 alter table sys_department add constraint fk_department_employee foreign key(manager_sn) references sys_employee(sn); 45 create table pet 46 ( 47 id number(11), 48 master_id number(11) not null, 49 name nvarchar2(50), 50 type_id number(11) not null, 51 health number(11) default 100 not null, 52 love number(11) default 100 not null, 53 prop1 nvarchar2(100), 54 prop2 nvarchar2(100), 55 prop3 nvarchar2(100), 56 adopt_time date not null, 57 status char(1) default 1 not null, 58 constraint pet_pk primary key(id), 59 constraint master_fk foreign key(master_id) references pet_master(id), 60 constraint type_fk foreign key(type_id) references pet_type(id) 61 ) 62 comment on table pet is '宠物';--注释 63 comment on column pet.name is '宠物昵称' 64 65 --创建序列 66 create sequence seq_name--序列名 67 start with start--起始值 68 increment by increment--增量 69 minvalue minvalue|nominvalue--最小值 70 maxvalue maxvalue|nomaxvalue--最大值 71 cycle|nocycle--用来指定达到最大值后或最小值后 72 cache cache|nocache--指定缓存中保留预分配的序列值 73 order|noorder --唯一性顺序性|唯一性 74 75 create sequence master_seq 76 start with 1 77 increment by 1 78 nomaxvalue 79 cache 10 80 81 alter sequence master_seq --修改序列 82 increment by 5 83 maxvalue 100000 84 nocycle 85 nocache 86 87 drop sequence master_seq --删除序列 88 s 89 90 --索引 91 create [UNIQUE/BITMAP] index [name] --UNIQUE 唯一 BITMAP 位图 null B树 92 on [table_name] --表名 93 (column_1|expression1 asc/desc,column_2|expression2 asc/desc,...) --column_1 列 expression1 函数 94 reverse 95 96 create unique index adopt_time_index 97 on pet(adopt_time desc) 98 99 create bitmap index type_id_bmp_index 100 on pet(type_id) 101 102 create index health_love_index 103 on pet(health,love) 104 105 create index to_char_index 106 on pet(to_char(adopt_time,'YYYY')) 107 108 create index pet_master_index 109 on pet(master_id) reverse 110 111 drop index pet_master_index 112 113 select * from pet
posted on 2014-08-04 12:54 JT808-Protocol 阅读(65) 评论(0) 收藏 举报
浙公网安备 33010602011771号