database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
ㆍMS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
MS-SQL Q&A 2127 게시물 읽기
No. 2127
시간이 너무 많이 걸릴때 한번 시도해 보셔요
작성자
석이
작성일
2005-07-19 15:45ⓒ
2005-07-19 15:46ⓜ
조회수
2,822

저희 사이트는 html 제너레이터를 이용해서 index.html 을 만들고 있음에도

불구하고 메인의 쿼리가 너무 오래 걸려서 여러게시판에서 골라올때

이렇게 한번 만들어 보았습니다.

이걸 스케줄러로 돌려주고 캐싱테이블에서 뽑아 쓰기 입니다. (실제 테이블입니다.)

 

여러 다른 디비도 이런식으로 연결해서 해보았는데 좋더군요

혹시라도 쓰고 싶다면 한번 써보세요

 

고수분은 더 좋은 방법있으면 좀 알려주세요

^^;

여기 질답란 인데 죄송 ~

저희는 디비가 여러대라서

create proc usp_make_Ctbl_mainNews
as
-- drop proc usp_make_Ctbl_mainNews
-- -------------------------------------------------------------------------------------------------------------------
-- 시작
-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
-- 참고 테이블
-- create table Ctbl_articleClass
-- (
-- dep varchar(20)
-- ,articleid varchar(20)
-- ,compcode char(2)
-- ,inputtime datetime
-- ,title varchar(150)
-- ,contents varchar(1000)
-- ,wowcode char(4)
-- ,cnt int
-- )

-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
-- 캐싱테이블의 멕스 값 + 1
declare @thisCount int
select @thisCount = isnull(max(cnt),0) + 1 from Ctbl_articleClass

-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
-- 결과값이 너무 많아서 일정량을 끊어온다.
declare @tmp_articleclass TABLE
(
idx int,
articleid varchar(20)
)
-- 중복값 제거를 위한 변수
declare @articleidHeader varchar(20)
declare @contents varchar(1000)
declare @compcode char(2)
declare @sql varchar(1000)
insert into @tmp_articleclass select top 1000 idx,articleid from articleclass order by idx desc

-- 1번
-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------

insert into Ctbl_articleClass
select top 1 '증권금융메인타이틀' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx
where (b.wowcode='W001') and (b.title not LIKE '_표]%' and b.title not LIKE '%사진]%')
order by b.ArticleDate desc

 


-- 중복값 제거를 위한 아이디값 찾기 및 컨텐츠 내용 불러오기
select @articleidHeader=articleid, @compcode = compcode from Ctbl_articleClass where dep ='증권금융메인타이틀' and cnt = @thisCount

set @sql = 'update Ctbl_articleClass set contents = (select substring(Contents,1,1000) from articlelist_'+@compcode+' where articleid ='''+ @articleidHeader+''') where dep =''증권금융메인타이틀'''
exec(@sql)

insert into Ctbl_articleClass
select top 5 '증권금융' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx where (wowcode='W001')
and b.articleid <> @articleidHeader
order by b.articledate desc


-- 2번
-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
insert into Ctbl_articleClass
select top 1 '주식시황메인타이틀' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx
where (b.wowcode='W002') and (b.title not LIKE '_표]%' and b.title not LIKE '%사진]%')
order by b.ArticleDate desc

-- 중복값 제거를 위한 아이디값 찾기

select @articleidHeader=articleid, @compcode = compcode from Ctbl_articleClass where dep ='주식시황메인타이틀' and cnt = @thisCount
set @sql = 'update Ctbl_articleClass set contents = (select substring(Contents,1,1000) from articlelist_'+@compcode+' where articleid ='''+ @articleidHeader+''') where dep =''주식시황메인타이틀'''
exec(@sql)

insert into Ctbl_articleClass
select top 5 '주식시황' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx where (wowcode='W002')
and b.articleid <> @articleidHeader
order by b.articledate desc


-- 3번
-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
insert into Ctbl_articleClass
select top 1 '업종뉴스메인타이틀' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx
where (b.wowcode='W004') and (b.title not LIKE '_표]%' and b.title not LIKE '%사진]%')
order by b.ArticleDate desc

-- 중복값 제거를 위한 아이디값 찾기
select @articleidHeader=articleid, @compcode = compcode from Ctbl_articleClass where dep ='업종뉴스메인타이틀' and cnt = @thisCount

set @sql = 'update Ctbl_articleClass set contents = (select substring(Contents,1,1000) from articlelist_'+@compcode+' where articleid ='''+ @articleidHeader+''') where dep =''업종뉴스메인타이틀'''
exec(@sql)

insert into Ctbl_articleClass
select top 5 '업종뉴스' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx where (wowcode='W004')
and b.articleid <> @articleidHeader
order by b.articledate desc


-- 4번
-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
insert into Ctbl_articleClass
select top 1 '해외뉴스메인타이틀' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx
where (b.wowcode='W008') and (b.title not LIKE '_표]%' and b.title not LIKE '%사진]%')
order by b.ArticleDate desc

-- 중복값 제거를 위한 아이디값 찾기
select @articleidHeader=articleid, @compcode = compcode from Ctbl_articleClass where dep ='해외뉴스메인타이틀' and cnt = @thisCount

set @sql = 'update Ctbl_articleClass set contents = (select substring(Contents,1,1000) from articlelist_'+@compcode+' where articleid ='''+ @articleidHeader+''') where dep =''해외뉴스메인타이틀'''
exec(@sql)

insert into Ctbl_articleClass
select top 5 '해외뉴스' dep , b.articleid,b.compcode, b.ArticleDate ,b.title,'' contents,b.wowcode, @thisCount cnt from
articleclass b
inner join
(
select max(idx) idx,articleid from @tmp_articleclass group by articleid
) a
on a.idx = b.idx where (wowcode='W008')
and b.articleid <> @articleidHeader
order by b.articledate desc

-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------
-- 데이터를 입력했으므로 예전 테이터를 지운다.
delete from Ctbl_articleClass where cnt < (select max(cnt) from Ctbl_articleClass)
-- -------------------------------------------------------------------------------------------------------------------
-- -------------------------------------------------------------------------------------------------------------------

-- for test
-- select * from Ctbl_articleClass

 

exec usp_make_Ctbl_mainNews

 

[Top]
No.
제목
작성자
작성일
조회
2130select 해서 CSV로 추출하기... 아래 질문 자문 자답입니다. [1]
커너
2005-07-20
2365
2129그런데 프로지저를 어케 실행시키믄되염? [1]
임민영
2005-07-19
2131
2128ms-sql스크립트를 쓰는뎅.. 계속 오류가 나는데염..
임민영
2005-07-19
2713
2127시간이 너무 많이 걸릴때 한번 시도해 보셔요
석이
2005-07-19
2822
2126inner join 에서 A.[open].. [4]
최장원
2005-07-19
1918
2125공백값을 null로 변경 하려면 [2]
베캄
2005-07-19
3520
2124프로시져안의 쿼리문의 top 에 변수값을 받을 경우 ... [1]
janis
2005-07-19
2603
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.016초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다