- --Oracle创建表
- create table t_test
- (
- test_id Number ,
- gender char(1),
- test_name nvarchar2(10) --注意最后一个字段结尾不能有分号
- )
-
- --Oralce向t_test表里插入数据
- insert into t_test(test_id,gender,test_name) values(1,0,'小明')
-
- --查询表
- select * from t_test
-
- --删除表
- drop table t_test
-
- --删除表数据
- delete from t_test where test_id=1
-
- --修改表数据
- update t_test set test_name='李明' where test_id=1
-
- --为t_test表的test_name字段创建一个单列索引,索引名为“ ix_test_name” 单列索引是基于单个列所建立的索引。
- create index ix_test_name
- on t_test(test_name)
-
- --为t_test表的test_name字段创建一个复合索引,索引名为“ ix_test” 复合索引是基于两列或是多列的索引,在同一张表上可以有多个索引,但是要求列的组合必须不同。
- create index ix_test
- on t_test(test_id,gender)
-
- --删除索引
- drop index ix_test
-
- /*
- 三、使用索引的原则 http://www.cnblogs.com/BeautyOfCode/archive/2010/09/22/1832906.html
-
- 使用原则:
-
- 1、在大表上建立索引才有意义。
-
- 2、在where子句或是连接条件上经常引用的列上建立索引。
-
- 3、索引的层次不要超过4层。
-
-
-
- 四、索引缺点分析
-
- 索引有一些先天不足:
-
- 1、建立索引,系统要占用大约为表的1.2倍的硬盘和内存空间来保存索引。
-
- 2、更新数据的时候,系统必须要有额外的时间来同时对索引进行更新,一维持数据和索引的一致性。
-
- 实践表明,不恰当的索引不但于事无补,反而会降低系统性能。因为大量的索引在进行插入、修改和删除操作时比没有索引花费更多的系统时间。
-
- 比如在如下字段建立索引应该是不恰当的:
-
- 1、很少或从不引用的字段。
-
- 2、逻辑型的字段,如男或女(是或否)等。
-
- 综上所述,提高查询效率是以消耗一定的系统资源为代价的,索引不能盲目的建立,这是考验一个DBA是否优秀的很重要的指标。
- */
|