본문 바로가기

DataBase

(31)
프로시저변경 트리거 보호되어 있는 글입니다.
Where 조건에서 Exists 써보기 where 1=1and exists(select 1 where @book_nm = ''union allselect 1 where @book_nm '' and tb.book_nm like + '%' + @book_nm + '%')
쿼리가 캐시를 탔는지 조회하기 실행한 쿼리가 캐시를 탔는지 안탔는지 조회해보는 쿼리입니다. 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')
프로시저 동적 쿼리파라미터 캐싱 ------ 1. 권장- 동적쿼리파라메터캐싱 --------- create proc upcl_text_tmp ( @user_id varchar(25) ) as declare @sql nvarchar(max), @params nvarchar(500); set @params = N'@user_id varchar(25)'; set @sql = 'select user_id from hunetc.dbo.thu_user_login where user_id = @user_id' execute sp_executesql @sql, @params, @user_id = @user_id; ------ 2. 동적쿼리 파라메터 캐싱 안됨--------- create proc upcl_text ( @user_id varchar(2..
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쿼리는 배제한 조회 입니다 ^^
Northwind database 다운받기 http://northwinddatabase.codeplex.com/releases/view/71634 위의 링크에서 northwind database backup파일을 받으실수 있습니다. 2003은 안되네요^^