⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 维勒斯.txt

📁 关于oracle和sql的书籍和ppt教程,非常好,本人珍藏品
💻 TXT
字号:
1.用insert into插入数据
alter table tab_2 modify name default '默认';


2.create sequence sq_20 start with 1 increment by 1;

3.
创建表
create table tab_20 (id long,name varchar2(6),sex varchar2(2),brithday date);

插入数据
declare 
begin
 for i in 1..1000000 loop
   insert into tab_20 values (sq_20.nextval,'新中国','女',to_date('1949-10-1','yyyy-mm-dd'));
 end loop; 
end;

改善数据,增加多样性
update tab_20 set name='台湾' where mod(id,2)=0;
update tab_20 set name='香港' where mod(id,3)=0;
update tab_20 set name='澳门' where mod(id,5)=0;
update tab_20 set brithday=to_date('1911-01-01','yyyy-mm-dd') where name='台湾';
update tab_20 set brithday=to_date('1997-07-01','yyyy-mm-dd') where name='香港';
update tab_20 set brithday=to_date('1999-12-24','yyyy-mm-dd') where name='澳门';


创建索引
B树 create index idx_tab_name on tab_20(name);
位图 create bitmap index idx_tab_sex on tab_20(sex);
函数 create index fidx_tab_brithday on tab_20(brithday);

按索引查询数据
select count(*) 叫做澳门的 from tab_20 where name='澳门';

叫做澳门的
----------
    200000


SQL> select count(*) 性别为女的 from tab_20 where sex='女';

性别为女的
----------
   1000000

SQL> 

SQL> select count(*) 比香港成立晚的 from tab_20 where brithday< to_date('1997-07-01','yyyy-mm-dd');

比香港成立晚的
--------------
        533333


4.
创建视图
create view tab_20_name_view as select * from tab_20 where name='澳门';
create view tab_20_sex_view as select * from tab_20 where sex='女';
create view tab_20_brithday_view as select * from tab_20 where brithday< to_date('1997-07-01','yyyy-mm-dd');


5.
索引是一把双刃剑,既可以提高数据检索的效率,又会影响系统DML操作的性能,因为系统进行DML操作后还要维护索引数据。新的SQL标准不提倡使用索引,建议用主键取代。

一般不需要为小表创建索引。
对于大表来说,如果经常查询的记录数目少于表中所有记录的15%,则可以考虑为该表创建索引。
应当为大部分列值不重复的列建立索引。

为取值范围很大的列创建B树索引,反之创建位图索引。
对于包含很多空值但不常查所有非空记录的列没有必要建立索引。
Oracle会自动为主键列和唯一列创建索引。



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -