Thursday, September 24, 2015

SSAS DMVs for Monitoring & Querying Meta-Data

-- List of Dimensions.
SELECT
[CATALOG_NAME] AS Database,
[CUBE_NAME] AS [Cube],
[DIMENSION_NAME] AS [Dimension]
FROM
$SYSTEM.MDSCHEMA_DIMENSIONS
ORDER BY DIMENSION_NAME


-- List of Measures, along with MDX Formula for Calculated Measures.
SELECT
[CUBE_NAME] AS [Cube],
[MEASUREGROUP_NAME] AS [MeasueGroup],
[MEASURE_NAME] AS [Measure],
[EXPRESSION] AS [Calculation]
FROM
$SYSTEM.MDSCHEMA_MEASURES
ORDER BY
[MEASURE_NAME]

-- Dimension-MeasureGroup Relation.
SELECT
[CUBE_NAME] AS [Cube],
[MEASUREGROUP_NAME] AS MeasureGroup,
[DIMENSION_UNIQUE_NAME] AS Dimension_Real_Name,
[DIMENSION_IS_VISIBLE] AS Dimension_Visible,
[DIMENSION_GRANULARITY] AS Dimension_Granularity
FROM
$SYSTEM.MDSCHEMA_MEASUREGROUP_DIMENSIONS
ORDER BY
[DIMENSION_UNIQUE_NAME]


-- Current Sessions along with Resource Usage & Last Executed Command.
-- This can also be used to identify long running queries.

select * from $system.discover_sessions ORDER BY SESSION_LAST_COMMAND_ELAPSED_TIME_MS DESC

-- TO kill a long running query, note the SESSION_SPID from the above query and execute the following XMLA command

<Cancel xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">

       <SPID>341157</SPID>

</Cancel>


-- Current Connections.
select * from $system.discover_connections

-- Current Commands. For Currently executing command, Command_End_Time will be blank.
select * from $system.discover_commands order by COMMAND_END_TIME



Thursday, September 10, 2015

Ten Reasons to Use SSDT Database Projects.

1.       Schema Compare

Find differences between 2 databases or between database and database project.

In Visual Studio
Go to View -> SQL Server Object Explorer.
Add SQL Server.
Once Server is added, Select a database and choose Schema Compare.






2.     Create a database project. 

Right click on a database and select Create New Project. 
Once the project is created, it can be checked in source control tool (GITS or TFS).


3.       Automated Deployment.

The database project can be published to target database. 

Right click on the database project and select publish. This synchronizes the schema of target database with database project. Any existing data in the target database is retained.




5. Deployment Script Generation.

You can generate a deployment script and examine it before publishing to target database.

Right Click on Database Project, Select Publish and Generate Script. 
The script once generated can be deployed using SSMS.



The Advanced button gives you additional deployment options like Take Backup Before Publish etc.

6.  Snapshot & DACPAC.

 DACPAC is a single database file that contains entire database schema.  When you do not have access to production server, you can generate DACPAC and hand it over to DBA. The DACPAC can be deployed using SSMS "Upgrade Data Tier Application Task".




To create DACPAC right click database project and select "Snapshot Project". This creates DACPAC in snapshots folder of project.



When you do not have source control, DACPAC can be used to capture point in time snapshot or major/minor versions.

7.       Build Time Validation 

Visual studio includes a local debug database, when database project is built, it is deployed to local database, if there are errors (invalid table references for example), they will show up during build time as errors.

8. Automated Testing.


9. Continuous Database Integration.