tsql with

Tsql теория > tsql with
10.12.2018 21:31:44



Статья:

WITH dek_encryption_state AS  
( 
    SELECT ISNULL(db_map.database_id, dek.database_id) AS database_id, encryption_state 
    FROM sys.dm_pdw_nodes_database_encryption_keys AS dek 
        INNER JOIN sys.pdw_nodes_pdw_physical_databases AS node_db_map 
           ON dek.database_id = node_db_map.database_id AND dek.pdw_node_id = node_db_map.pdw_node_id 
        LEFT JOIN sys.pdw_database_mappings AS db_map 
            ON node_db_map .physical_name = db_map.physical_name 
        INNER JOIN sys.dm_pdw_nodes AS nodes 
            ON nodes.pdw_node_id = dek.pdw_node_id 
    WHERE dek.encryptor_thumbprint <> 0x 
) 
SELECT TOP 1 encryption_state 
       FROM  dek_encryption_state 
       WHERE dek_encryption_state.database_id = DB_ID(''AdventureWorksPDW2012 '') 
       ORDER BY (CASE encryption_state WHEN 3 THEN -1 ELSE encryption_state END) DESC;