728x90
반응형
CURSOR
DECLARE @database VARCHAR(50)
DECLARE db_cursor CURSOR FOR select name FROM sys.databases
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @database
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @database
FETCH NEXT FROM db_cursor INTO @database
END
CLOSE db_cursor
DEALLOCATE db_cursor
WHILE
with CTE AS (
select name from sys.databases
)
select name into #query from CTE
DECLARE @name VARCHAR(50)
WHILE EXISTS (select top (1) name FROM #query)
BEGIN
set @name = (select top(1) name from #query)
print @name
delete from #query where name = @name
END
DROP TABLE #query
728x90
반응형
'MSSQL' 카테고리의 다른 글
MSSQL] 샘플 데이터 만들기 (0) | 2023.04.24 |
---|---|
MSSQL] PIVOT, UNPIVOT, GROUPING SETS, ROLLUP, CUBE (0) | 2023.04.14 |
DB 암호화/복호화 (0) | 2021.09.08 |
MSSQL] xmlParseCharRef: invalid xmlChar value 26 오류해결 (0) | 2020.12.03 |
MSSQL] 구분자로 문자열 split하여 Table로 변환하기 (0) | 2020.10.15 |
댓글