MS SQL

· MS SQL
○ BEGIN - ENDBEGIN으로 시작하고 END로 끝나는 흐름 제어 언어 키워드쿼리 블럭이라고 함  ○ IFIF (조건문) BEGIN 참일때 실행 ENDELSE BEGIN 거짓일때 실행 END     ○ WHILEWHILE (조건문) BEGIN 조건이 TRUE면 반복 실행될 쿼리문 END  ○프로시저 저장 프로시저>> 필요할 때 호출하여 사용할 수 있는 SQL 문쿼리문들의 집합으로 어떤 동작을 여러 쿼리를 거쳐서 일괄적으로 처리할 때 사용됨 SQL Server의 성능 향상과 유지보수 및 재활용에 좋고 보안을 강화할 수 있다는 장점이있음  기본 문법 CREATE PROCEDURE name AS BEGIN SELECT 1 END GO 실행할때는 EXEC를 사용..
· MS SQL
○ PlacementsYou are given three tables: Students, Friends and Packages. Students contains two columns: ID and Name. Friends contains two columns: ID and Friend_ID (ID of the ONLY best friend). Packages contains two columns: ID and Salary (offered salary in $ thousands per month).Write a query to output the names of those students whose best friends got offered a higher salary than them. Names mu..
· MS SQL
○ Weather Observation Station 5 Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.The STATION table is described as follows:where LAT_N is the northern latitude and LONG_W is the weste..
· MS SQL
○ Top Competitors Julia just finished conducting a coding contest, and she needs your help assembling the leaderboard! Write a query to print the respective hacker_id and name of hackers who achieved full scores for more than one challenge. Order your output in descending order by the total number of challenges in which the hacker earned a full score. If more than one hacker received full scores..
· MS SQL
○ MS SQL 문제 1 Pivot the Occupation column in OCCUPATIONS so that each Name is sorted alphabetically and displayed underneath its corresponding Occupation. The output column headers should be Doctor, Professor, Singer, and Actor, respectively. Note: Print NULL when there are no more names corresponding to an occupation. Input Format The OCCUPATIONS table is described as follows: Occupation will o..
· MS SQL
SSMS 주석생성 단축키 : Ctrl + K + C 주석 제거 : Ctrl + K + U 변수 지정 변수명 앞에 @가 붙음 DECLARE [변수이름] [데이터 형식] [=기본값,옵션] ex) DECLARE @변수1 INT = 0, @ 변수 2 INT = 0 SET @변수1 = 30 SET @변수2 = 0 SET 대신 SELECT 로 변수에 값을 저장할 수 있음 트랜잭션 특정한 목적을 위해 여러 명령을 수행 중 문제 발생시 이미 완료된 작업 모두를 취소하는 기능 시스템변수인 @@ERROR와 @@ROWCOUNT 와 같이 주로 쓰인다 DECLARE @INT_실패여부 INT SET @INT_실패여부 = 0 ----- 트랜잭션 시작 ----- BEGIN TRAN ----- UPDATE 후 에러 및 처리 건수를 체..
· MS SQL
SSMS (SQL Server Management Studio) SQL Server를 포함해 Azure SQL Database와 같은 모든 SQL 인프라를 관리하는 통합환경도구 [기본 단축키] ctrl + n : 쿼리창 켜기 f5 : 쿼리문 실행 테이블명 드래그 후 alt + f1 : 테이블의 열 목록 확인 가능 그 외 단축키 관련 참고 내용 https://unions5.tistory.com/99 CRUD 관련 내용 In( 'a' , 'b' , 'c' ) : a,b,c 중 하나라도 있으면 true Null 값/ 아닌 값 찾기 : IS NULL / IS NOT NULL 상위 n개 조회 : Select TOP n 값 지정한 행 개수만큼 건너뛰고 출력 : OFFSET n(행 개수) ROWS >> OFFSET은..
s2h15
'MS SQL' 카테고리의 글 목록