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 5795 게시물 읽기
No. 5795
안녕하세요 insert into 질문 드립니다.
작성자
전명식(fernandy)
작성일
2010-11-06 18:34ⓒ
2010-11-06 18:39ⓜ
조회수
6,513

안녕하세요 이제 막 쿼리를 배우고 있습니다.

질문을 상세하게 잘 설명해야 할텐데 걱정이네요..

 

쿼리는 아래와 같습니다.

 

delete u_i_lp_unit
insert into u_i_lp_unit
select v.*
from
(
select i.*
          from (select d.degree_cd,d.business_group_cd,d.area_type_cd,d.gubun,d.sup_type_cd,e.site_area_avg as qty
                    from (select c.degree_cd,c.business_group_cd,c.area_type_cd,c.gubun,c.sup_type_cd, c.qty
                              from (select distinct a.degree_cd,a.business_group_cd,a.area_type_cd, b.gubun,
                                                                (select b.supply_type_cd
                                                                 from u_i_supply_type_npms b
                                                                 where a.sup_type_cd = b.supply_type_cd) as sup_type_cd,0 as qty
                                       
                                        from u_i_lp_zone_avg a ,  (select gubun from u_i_lp_temp )  as b) as c
   
                               where ((c.gubun <> '연면적' and c.sup_type_cd like 'F%' or c.sup_type_cd like 'GA')
                                          or (c.gubun = '연면적' and sup_type_cd = 'GA'))) as d , u_i_lp_data e
                   
                    where d.degree_cd = e.degree_cd
                        and d.business_group_cd = e.business_group_cd
                        and d.area_type_cd = e.area_type_cd
                        and d.sup_type_cd = e.sup_type_cd) as i
         
          where i.gubun in('대지면적')


          union all


          select c.degree_cd,c.business_group_cd,c.area_type_cd,c.gubun,c.sup_type_cd, c.qty
          from (select distinct a.degree_cd,a.business_group_cd,a.area_type_cd, b.gubun,
                                            
                                               (select b.supply_type_cd
                                                 from u_i_supply_type_npms b
                                                 where a.sup_type_cd = b.supply_type_cd) as sup_type_cd,0 as qty
                   
                    from u_i_lp_zone_avg a ,  (select gubun from u_i_lp_temp )  as b) as c
         
           where (((c.gubun <> '연면적'  and c.sup_type_cd like 'F%' or c.sup_type_cd like 'GA') or (c.gubun = '연면적' and sup_type_cd = 'GA'))
               and c.gubun <> '대지면적')

) as v
order by v.business_group_cd,v.area_type_cd,v.gubun

 

---------------Select 부분만 드레그하여 실행하면 오류는 없습니다 다만, insert into를 할 때 아래와 같은 오류가 발생합니다.-------------

 

Attempt to insert duplicate key row in object 'u_i_lp_unit' with unique index 'u_i_lp_uni_8663073151'
 Msg: 2601, Level: 14, State: 1
 Server: sybase_pms, Line: 2 

쿼리가 지저분하여 정확한 답변을 꼭 원하지는 않습니다.  스스로 해결할 의지도 있으니 어떠한 도움이라도 고맙게 받겠습니다. 

고견 기다리겠습니다. (__)

이 글에 대한 댓글이 총 2건 있습니다.

에러 메시지의 내용은 u_i_lp_unit 테이블에 중복 허용을 막는 제약 조건이 걸려 있는데 이를 위반 했다는 것입니다.

즉, from 절의 데이터가 중복 값을 가지고 있다는 것이죠..

u_i_lp_unit 테이블에 pk가 설정되어 있는 컬럼이 어떤 것인지 확인해 보시고 해당 컬럼을 기준으로 중복 값을 한번 체크해 보시죠...

손님님이 2010-11-08 10:04에 작성한 댓글입니다. Edit

도움 감사합니다.

 

해결 하였습니다. (__)

전명식(fernandy)님이 2010-11-08 21:09에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
5798mysql 의 SP 를 mssql의 SP 로 변환문제 [1]
이동훈
2010-11-09
6379
5797linked server에 대해 선배님들의 조언을 구합니다. [1]
박태은
2010-11-08
8349
5796도움을 요청합니다. ㅜㅜ
박태은
2010-11-08
5761
5795안녕하세요 insert into 질문 드립니다. [2]
전명식
2010-11-06
6513
5794mysql 5.1 파티셔닝 관련
라이
2010-11-05
5700
5793DB 미러링 모니터 연결 문제??
정두현
2010-11-04
7008
5792Trigger 예문좀 ..
써니
2010-11-03
5672
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.019초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다