반응형

Database/SQL Server 81

SQL Server - Grouping Sets 함수 Grouping Sets in SQL Server

그룹핑 셋 Grouping Sets 함수 2008년에 소개된 이 기능은 다음과 같은 예시를 간단하게 해결하기 위한 것이다. Select Country, Gender, Sum(Salary) as TotalSalary From Employees Group By Country, Gender UNION ALL Select Country, NULL, Sum(Salary) as TotalSalary From Employees Group By Country UNION ALL Select NULL, Gender, Sum(Salary) as TotalSalary From Employees Group By Gender UNION ALL Select NULL, NULL, Sum(Salary) as TotalSalary Fr..

Database/SQL Server 2020.12.15

SQL Server - 테이블 반환 매개변수 Table Valued Parameters in SQL Server

테이블 반환이란 새로운 기능은 2008년에 소개되었다. 테이블 반환 매개변수는 테이블(여러개의 데이터 행을 가지고 있는)이 어플리케이션 또는 T-SQL에서 부터 저장 프로시저에 매개변수로 전달 될 수 있다. 2008년 전에는 매개변수로 테이블을 전달할 수 없었다. Table-Valued Parameter is a new feature introduced in SQL Server 2008. Table-Valued Parameter allows a table(i.e multiple rows of data) to be passed as a parameter to a stored procedure from T-SQL code or from an application. Prior to SQL Server 2008..

Database/SQL Server 2020.12.14

SQL Server - Where절과 Having절의 차이 Difference between where and having in SQL Server

둘 다 조건을 주는 절인데 시작점이 다르다. Where은 조건을 주어 필터링을 하고 Having은 나온 결과를 필터링한다. 성능면에서 where가 좋다. 그러니 가능하면 having의 사용을 피하는게 좋다. From a performance standpoint, HAVING is slower than WHERE and should be avoided when possible. SELECT Product, SUM(SaleAmount) AS TotalSales FROM Sales WHERE Product in ('iPhone', 'Speakers') GROUP BY Product SELECT Product, SUM(SaleAmount) AS TotalSales FROM Sales GROUP BY Produc..

Database/SQL Server 2020.12.12

SQL Server - Select into 구문 / Select into statement in SQL Server

SELECT INTO 구문 이란? SQL Server에서의 SELECT INTO은 새로운 테이블에 넣을 데이터들을 다른 하나의 테이블에서 선택한다. The SELECT INTO statement in SQL Server, selects data from one table and inserts it into a new table SQL Server에서 SELECT INTO 구문이 할 수 있는 것들 SELECT INTO statement in SQL Server can do the following things: 1. 복제 가능. 백업할 때 유용함 Copy all rows and columns from an existing table into a new table. This is extremely usefu..

Database/SQL Server 2020.12.12

SQL Server - 로그인 트리거 Logon Triggers

Logon Triggers는 무엇인가 Logon Triggers는 이름에서 알 수 있듯이 로그인을 관리하는 트리거이다. 로곤 트리거는 로그인 인증 단계가 끝난 후 사용자의 세션이 준비되기전에 시작된다. As the name implies Logon triggers fire in response to a LOGON event. Logon triggers fire after the authentication phase of logging in finishes, but before the user session is actually established. Logon 트리거 사용처 Logon triggers can be used for 1. 로그인 활동 추적 Tracking login activity 2. SQ..

Database/SQL Server 2020.12.12

SQL Server - DDL 트리거 이용하여 테이블의 변화 감지 Audit Table changes in SQL Server

CREATE TRIGGER tr_AuditTableChanges ON ALL SERVER FOR CREATE_TABLE, ALTER_TABLE, DROP_TABLE AS BEGIN Select EventData() END 이렇게 하면 XML포맷의 Event_instance가 날라온다. CREATE_TABLE 2020-12-11T15:27:58.700 79 LAPTOP-SKVGRGJD\MSSQLSERVER01 LAPTOP-SKVGRGJD\Home dbo sampleDB dbo TableChanges TABLE Create table Tablechanges ( DatabaseName nvarchar(250), TableName nvarchar(250), EventType nvarchar(250), Login..

Database/SQL Server 2020.12.12

SQL Server - 저장 프로시저로 트리거 순서 설정 / Trigger Execution Order

서버 범위 트리거는 항상 데이터베이스 단위 트리거보다 먼저 실행된다. Server scoped triggers will always fire before any of the database scoped triggers 그리고 sp_settriggerorder 라는 저장 프로시저를 통하여 실행 순서를 먼저 지정할 수 있다. Using the sp_settriggerorder stored procedure, you can set the execution order of server-scoped or database-scoped triggers Parameter Description @triggername Name of the trigger @order Value can be First, Last or Non..

Database/SQL Server 2020.12.12

SQL Server - DDL(Data Definition Language) 트리거 trigger에 대해

DDL 트리거는 무엇인가 ? What are DDL triggers ? DDL 트리거는 DDL 이벤트에 실행으로 반응한다. DDL과 유사한 작업을 수행하는 특정 시스템에 저장 프로시저도 DDL 트리거를 실행할 수 있다. DDL triggers fire in response to DDL events-CREATE, ALTER, and DROP(Table, Function, Index, Stored Procedure etc...). Certain system stored Procedures that perform DDL-like operations can also fire DDL triggers. 혹시 DDL 이벤트 리스트가 더 보고 싶다면 참고. docs.microsoft.com/en-us/sql/relat..

Database/SQL Server 2020.12.12

SQL Server - Cross apply & Outer apply in SQL Server

- 2005년에 소개된 APPLY 연산자는 table-valued function(테이블 리턴 함수)에 조인을 할 때 쓰인다.The APPLY operator introduced in SQL Server 2005, is used to join a table to a table-valued function. - APPLY 연산자의 오른쪽에 있는 테이블-리턴 함수는 왼쪽 테이블 각 행마다 호출이 된다.The Table Valued Function on the right hand side of the APPLY operator gets called for each row the left(also called outer table)table APPLY 연산자의 종류 APPLY Operator types - CR..

Database/SQL Server 2020.12.12

SQL Server - UNION , INTERSECT , EXCEPT 연산자

UNION 연산자는 오른쪽, 왼쪽 쿼리에 있는 모든 고유한 값을 리턴한다. UNION ALL은 중복값도 포함시켜 리턴한다. UNION operator returns all the unique rows from both the left and the right query. UNION ALL includes the duplicates as well INTERSECT 연산자는 왼쪽과 오른쪽에서 공통의 고유한 행만 보여준다. 교차로의 INTERSECTION 을 떠올리면 쉽겠다. INTERSECT operator retrieves the common unique rows from both the left and the right query EXCEPT 연산자는 오른쪽에 없는 왼쪽에서만 고유한 값을 결과로 가져온다..

Database/SQL Server 2020.12.11
반응형