본문 바로가기

DataBase/Ms Sql

(17)
특장한 날짜로 부터 주차의 시작 날짜 가져오기 DATEADD(week, (datepart(week, getdate()) - datepart(week, study_start_date) ), DATEADD(DAY, @@datefirst - DATEPART(weekday, CAST(YEAR(GETDATE()) AS VARCHAR) + '-01-01') - 6, CAST(YEAR(GETDATE()) AS VARCHAR) + '-01-01')),DATEADD(week, (datepart(week, getdate()) - datepart(week, study_start_date) ), DATEADD(DAY, @@datefirst - DATEPART(weekday, CAST(YEAR(GETDATE()) AS VARCHAR) + '-01-01') , CAST(YE..
Ms Sql replace select replace( menu_path, '/Lecture', '/Lecture2') from clsc..tcl_menuwhere company_seq = 472 and menu_path like '%/Lecture%'
CTE 사용 ;with listas(select c.* from clsc.dbo.tcl_process_category cinner join clsc.dbo.tcl_process_category_study son c.company_seq = s.company_seqand c.category_no = s.category_nowhere s.company_seq = @company_seqand s.cp_code = @cp_cdand s.study_cd = @process_cdunion allselect c.* from clsc.dbo.tcl_process_category cinner join list lon c.company_seq = l.company_seqand c.category_no = l.parent_categor..
try catch문 http://polyphagia.egloos.com/264013위의 블로그에서 발췌한 내용입니다. 2005이상부터 적용된다. begin try begin tran insert into aaa values () insert into bbb values () commit tran end try begin catch print error_message() rollback tran end catch
프로시저변경 트리거 보호되어 있는 글입니다.
Where 조건에서 Exists 써보기 where 1=1and exists(select 1 where @book_nm = ''union allselect 1 where @book_nm '' and tb.book_nm like + '%' + @book_nm + '%')
Update시 테이블 이름 Alias이용 update a set a.reg_id ='mjg7822' from table as a where a.join_seq = 3 위와 같이 alias로 테이블 이름을 주고 해야 좀더 안전한 업데이트가 되네요 제가 한번 디비 전체 업데이트 한적 있는데... 아찔 했습니다. alias를 쓰는편이 좀더 안전하다고 할수 있어요 ^^
실행한 쿼리가 캐시를 탔는지 안탔는지 조회 select * from sys.dm_exec_cached_plans as cp CROSS APPLY sys.dm_exec_sql_text(plan_handle) as qt where text like '%실행쿼리를식별할수있는문자열%' and objtype not in ('Adhoc') 위의 코드는 adhoc쿼리는 배제한 조회 입니다 ^^