반응형

전체 글 1480

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

맥북 터치바에 자동 완성으로 작성된 글

하지만 아직 실감이 나지 않는다 해도 과언이 아니다 아무리 새로운 매체라 하더라도 새로운 시작을 알렸다 이 때문에 일각에서는 이번 사건을 계기로 표절 시비와 관련된 명확한 기준이 없어 보인다 고도 말했다 데일리안 스포츠 엔터테인먼트 전문 미디어 콘텐츠 제작 및 논평 기사를 다루며 웃음을 자아냈다 이 때문에 이번 시즌 소속팀 경기에 출전하고 있는 국군체육부대 소속 의원 다수가 해당 업체에서 제공한 것으로 나타났다 사라지는 것이 좋을 것이다 이렇게 봅니다 성인과 달리 이 같은 내용의 진위 논란에 대해 적극 해명할 기회를 잡았다 해도 이 🦷 머리와 어깨로 호수비를 펼친 것도 아니다 이렇게 평가할 것 같다 이렇게 되면 야구의 수준은 세계 🌍 자동차 연맹의 명예를 훼손한 사람들에게 법적 근거가 없어 보이는 것은 ..

etc. 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

SQL Server - Intersect 연산자(operator)

Intersect 연산자는 왼쪽 쿼리와 오른쪽 쿼리의 공통된 레코드를 검색한다.(교집합) Intersect operator retrieves the common records from both the left and the right query of the Intersect operator. - SQL Server 2005에 소개됨. Introduced in SQL Server 2005 - 양쪽 두 쿼리에서 열의 개수와 순서가 같아야 한다. The number and the order of the columns must be same in both the queries - 데이터 타입은 같거나 반드시 호환이 가능해야 한다. The data types must be same or at least compa..

Database/SQL Server 2020.12.11

SQL Server - Except 연산자(operator)

EXCEPT 연산자는 오른쪽 쿼리 결과에 없는 왼쪽 쿼리에서만 있는 고유한 행을 리턴한다. EXCEPT operator returns unique rows from the left query that aren't in the right query's results. - SQL Server 2005에 소개되었다. Introduced in SQL Server 2005 - 열의 개수와 순서는 두 쿼리에서 동일해야 한다. The number and the order of the columns must be the same in both the queries --안되는 경우 Select Name, Id, Gender from TableA Except Select Name, Id from TableB --컬럼의 숫..

Database/SQL Server 2020.12.11

SQL Server - 데이터베이스 교착 상태 Database Deadlock

교착 상태란? What is a deadlock? 데이터베이스에서의 교착 상태는 두 개나 그 이상의 프로세스가 자신의 리소스를 잠가버리고 서로의 리소스에 request를 하는 것을 말한다. 한마디로 아다리가 맞지 않아 서로 일을 하지 못하는 상태이다. 각 트랜잭션은 request로 잠금이 풀리길 기다리기 때문에 더 이상 진행이 될 수 없다. In a database, a deadlock occurs when two or more processes have a resource locked, and each process requests a lock on the resource that another process has already locked. Neither of the transactions here..

Database/SQL Server 2020.12.11

SQL Server - 동시에 일어나는 트랜잭션 Concurrent Transactions

트랜잭션이란 ? 트랜잭션은 데이터베이스에 저장된 데이터를 변경하는 명령문의 집합이다. 예전에 포스트한 글에도 개념 설명이 있지만 여기서도 또 나온다. 트랜잭션은 단일 작업 단위로 취급된다. A transaction is a group of commands that change the data stored in a database. A transaction, is treated as a single unit of work. 동시에 일어나는 트랜잭션은 은행으로 예를 들어 생각하면 쉽다. -- Transfer $100 from Mark to Mary Account BEGIN TRY BEGIN TRANSACTION UPDATE Accounts SET Balance = Balance - 100 WHERE Id =..

Database/SQL Server 2020.12.10

SQL Server - 재사용 가능한 스크립트 Re-runnable sql server script

재사용 가능한 스크립트란 ? 마구재사용을 해도 에러가 나지 않는 스크립트를 말한다. USE [Sample] Create table tblEmployee ( ID int identity primary key, Name nvarchar(100), Gender nvarchar(10), DateOfBirth DateTime ) --위의 쿼리가 하려는 것을 재사용 가능하게 만든 것 Use [Sample] If not exists (select * from information_schema.tables where table_name = 'tblEmployee') Begin Create table tblEmployee ( ID int identity primary key, Name nvarchar(100), Gend..

Database/SQL Server 2020.12.10

SQL Server - 모든 테이블의 리스트 T-SQL query

SQL sever management studio 에서 특정 데이트베이스의 테이블 리스트를 불러오기 위해 쓸 수 있는 3가지의 쿼리가 있음. -- Gets the list of tables only Select * from SYSOBJECTS where XTYPE = 'U' -- Gets the list of tavbles only Select * from SYS.TABLES -- Gets the list of tables and views Select * from INFORMATION_SCHEMA.TABLES -- Gets the list of different object types(XTYPE) in da database Select Distinct XTYPE from SYSOBJECTS -- Get..

Database/SQL Server 2020.12.10

SQL Server - 서브 쿼리 Subqueries, 상관 서브 쿼리 Correlated sub query

example 문제 한번도 안 팔린 제품은 무엇인가? Select Id, Name from tblProducts where Id NOT IN (Select distinct ProductId from tblProductsales) Join Select tblProducts.Id, Name from tblProducts left join tblProductSales on tblProducts.Id = tblProductSales.ProductId where tblProductSales.ProductId is null 문제 Name이랑 TotalQuantity sold 를 나타나게하는 쿼리가 필요 Subquery Select Name, (Select SUM(QuantitySold) from tblProduct..

Database/SQL Server 2020.12.09

SQL Server - 트랜잭션 (Transaction)

트랜잭션이란 ? 트랜잭션은 데이터베이스에 저장된 데이터의 변경 명령문의 집합이다. 트랜잭션은 단일 개념으로 취급되며 성공하던지 실패하던지 둘 중하나이다. 진행되다가 중간에 에러가 나거나 문제가 생기면 롤백이 된다. 이로써 데이터 베이스의 무결성을 유지한다. What is a Transaction ? A transaction is a group of commands that change the data stored in a database. A transaction, is treated as a single unit. A transaction ensures that, either all of the commands succeed, or none of them. If one of the commands in..

Database/SQL Server 2020.12.09

SQL Server - 에러 처리 Error handling(@@ERROR, TRY...CATCH)

SQL server 2000 - @@ERROR SQL server 2005 & later - Try...Catch 1. SQL server 2000 RAISERROR('Error Message', ErrorSeverity, ErrorState) 에러 만들기 Severity level = 16 (사용자가 수정할 수 있는 일반적인 오류를 나타냄 Indicates general errors that can be corrected by the user) 0~25 의 숫자로 심각도를 설정 가능함,,, 0~18 일반적 19~25 WITH LOG옵션이 필요함 20이상 부터는 치명적인 오류로 간주함 State = Number between 1 & 255. RAISERROR 는 0 ~ 255 정수만 사용할 수 있음. @..

Database/SQL Server 2020.12.09

SQL Server - 피벗 오퍼레이터 (PIVOT Operator)

피벗은 테이블을 효과적으로 순환하여 한 열의 고유값을 여러열로 변환하는데 사용할 수 있는 SQL server operator이다. Pivot is a sql server operator that can be used to turn unique values from one column, into multiple columns in the output, there by effectively rotating a table. Example, Select SalesAgent, Korea, US, UK from ( Select SalesAgent, SalesCountry, SalesAmount from tblProductSale ) as SourceTable PIVOT ( SUM(SalesAmount) FOR Sa..

Database/SQL Server 2020.12.09
반응형