SELECT
N'CREATE PARTITION FUNCTION '
+ QUOTENAME(pf.name)
+ N'(' + t.name + N')'
+ N' AS RANGE '
+ CASE WHEN pf.boundary_value_on_right = 1 THEN N'RIGHT' ELSE N'LEFT' END
+ ' FOR VALUES('
+
(SELECT
STUFF((SELECT
N','
+ CASE
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') IN(N'char', N'varchar')
THEN QUOTENAME(CAST(r.value AS nvarchar(4000)), '''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') IN(N'nchar', N'nvarchar')
THEN N'N' + QUOTENAME(CAST(r.value AS nvarchar(4000)), '''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') = N'date'
THEN QUOTENAME(FORMAT(CAST(r.value AS date), 'yyyy-MM-dd'),'''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') = N'datetime'
THEN QUOTENAME(FORMAT(CAST(r.value AS datetime), 'yyyy-MM-ddTHH:mm:ss'),'''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') IN(N'datetime', N'smalldatetime')
THEN QUOTENAME(FORMAT(CAST(r.value AS datetime), 'yyyy-MM-ddTHH:mm:ss.fff'),'''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') = N'datetime2'
THEN QUOTENAME(FORMAT(CAST(r.value AS datetime2), 'yyyy-MM-ddTHH:mm:ss.fffffff'),'''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') = N'datetimeoffset'
THEN QUOTENAME(FORMAT(CAST(r.value AS datetimeoffset), 'yyyy-MM-dd HH:mm:ss.fffffff K'),'''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') = N'time'
THEN QUOTENAME(FORMAT(CAST(r.value AS time), 'hh\:mm\:ss\.fffffff'),'''') --'HH\:mm\:ss\.fffffff'
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') = N'uniqueidentifier'
THEN QUOTENAME(CAST(r.value AS nvarchar(4000)), '''')
WHEN SQL_VARIANT_PROPERTY(r.value, 'BaseType') IN (N'binary', N'varbinary')
THEN CONVERT(nvarchar(4000), r.value, 1)
ELSE CAST(r.value AS nvarchar(4000))
END
FROM sys.partition_range_values AS r
WHERE pf.[function_id] = r.[function_id]
FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)'),1,1,N'')
)
+ N');'
FROM sys.partition_functions pf
JOIN sys.partition_parameters AS pp ON
pp.function_id = pf.function_id
JOIN sys.types AS t ON
t.system_type_id = pp.system_type_id
AND t.user_type_id = pp.user_type_id
WHERE pf.name = N'PF_Year';
'SQL SERVER' 카테고리의 다른 글
전체DB들의 LDF SIZE확인 (0) | 2023.09.11 |
---|---|
실행중인 SQL확인 (0) | 2023.09.11 |
Agent Job 실패확인 (0) | 2023.09.11 |
synonym의 base object 조회 (0) | 2022.12.15 |
전체Table Size 확인 (0) | 2022.11.08 |
CREATE PROC usp_chk_long_run_query
AS
SET NOCOUNT ON;
SELECT COUNT(*) AS long_run_count
FROM sys.dm_exec_sessions AS s
JOIN sys.dm_exec_requests AS r ON r.session_id = s.session_id
CROSS APPLY sys.Dm_exec_sql_text(r.sql_handle) AS st
WHERE r.session_id != @@SPID
AND r.total_elapsed_time > (30 * 60 * 1000)
AND command NOT IN (
'BACKUP DATABASE'
,'KILLED/ROLLBACK'
)
AND DATEPART(HH, getdate()) BETWEEN 8 AND 20
AND DATEPART(WEEKDAY, GETDATE()) BETWEEN 2 AND 6
AND wait_type NOT IN('SP_SERVER_DIAGNOSTICS_SLEEP', 'OLEDB', 'TRACEWRITE')