select title_id, price
from titles with (index(0)) -- 인덱스를 없애고 출력(권장하지 않음)
where title_id ='bu1032'
sp_helpindex titles
select * from sysindexes
where id= object_id('titles')
select * from orders -- 클러스터 쿼리를 사용해야함
where employeeid=5 -- Range Query(같은 항목의 내용들을 출력함으로 포인트 쿼리가 아님)
select * from orders
where orderid=10248 --point Query (한가지의 값만을 출력)
select * into ord from orders
create unique index idx1 on ord(orderid) -- 인텍스 만듬
create index idx2 on ord(employeeid)
select * from ord with (index(idx2)) -- 포인트 쿼리를 강제 사용
where employeeid=5
select * from ord
where orderid=10248
--기본키는 넌 클러스터 색인이 되어야 한다
--사번 primary key nc
--이름 nc -- 한명, 한명의 사람을 찾는데는 noncluster가 용이
--부서
--직급
--입사일 cl -- 입사일이 같은 사람을 찾을 때는 noncluster 사용
--전화번호
-- 커버된 클러스터는 NonCluster에서만 적용됨
select 부서, 번호 from... where 번호 <20 --leaf 에서 원하는 데이터를 찾는다(속도 증가)
-- 데이터페이지 전에 만들어진 leaf 레벨에서 데이터를 찾아오기 때문에 속도가 빠르다.(커버드)
select 부서, 번호, 성별, 주소, 전화 from ... where 번호 <30
-- 모든 항목을 다 가져오기 때문에 데이터 페이지까지의 접근이 필수이다 그렇기에 커버드가 아님
-- 커버드 인덱스 예제들(복합키-composite key 설정하여 사용)
select city from employees where city='
select name from employees where city='
select count(city) from employees where city='
select count(name) from employees where city ='
select count(*) from employees where city='
select count(city) from employees where city='
create table test
(
id int identity,
name char(80),
cd datetime default getdate())
declare @i smallint
set @i=0
while @i<10000
begin
set @i=@i+1
insert into test values(@i*3 %40, default)
end
select top 1000 * from test
create nonclustered index idx -- 복합 키 설정
on test(name, id)
select id from test where id=300 --실행계획 표시에 'index 스캔' 표시
select name from test where id=300 --실행계획 표시에 'index 스캔' 표시
select * from test where id=300 -- 실행계획 표시에 'table 스캔' 표시(데이터 페이지검색)
create index indexName
on tablename(columnName) with drop_exsiting, fillfactor=80, pad_index=40
--fillfactor은 leaf레벨에 공간 채움, pad_index는 root레벨에 공간채움
--속성에서 지정해주지 않고, 위와 같이 하나씩 설정해준다
--drop_exsiting를 사용하면 넌클러스터에서 클러스터로 바꿔주는데 시간이 절약됨
dbcc dbreindex (authors, '', 70)-- authors에 대해 모두 70%의 공간을 남겨둔다
dbcc dbreindex ('pubs.dbo.authors', upkcl_auidind, 80) -- 인텍스에 80%의 공간을 남겨둔다
dbcc showcontig(test) -- 테이블의 정보를 표시
- 스캔한 페이지................................: 130
- 스캔 밀도[최적:실제].......: 94.44% [17:18]
- 평균 페이지 밀도(전체).....................: 95.97%
delete test where id>9500
create index idx on test(id, name) with drop_existing
delete test where id %3=0
'연구개발 > DBA' 카테고리의 다른 글
MS-SQL문 강좌 13장 (0) | 2010.08.01 |
---|---|
MS-SQL문 강좌 12장 (0) | 2010.08.01 |
MS-SQL문 강좌 9 장 (0) | 2010.08.01 |
MS-SQL문 강좌 8 장 (0) | 2010.08.01 |
MS-SQL문 강좌 7 장 (0) | 2010.08.01 |