Chris Pietschmann

husband, father, hacker, entrepreneur, futurist, innovator, autodidact


SQL Azure: Calculate Database Usage Percentage of Max Size

Some times it can be useful to programmatically monitor your SQL Azure database usage statistics. Luckily, there is some short SQL code that can be run on the database to check how much disk space is currently used and what the currently allotted max database size is. The following script does just that. DECLARE @dbName nvarchar(255) = '{database_name}'; DECLARE @Max BIGINT = CONVERT(BIGINT, (SELECT DATABASEPROPERTYEX(@dbName , 'MaxSizeInBytes'))); DECLARE @Used BIGINT = ( SELECT ... [More]

SQLinq: Use LINQ to generate Ad-Hoc, strongly typed SQL queries

SQLinq is a new library that allows ad-hoc SQL code to be generated at runtime in a strongly typed manner that allows for compile time validation of your SQL code. Why SQLinq? SQLinq is built with the core idea of simplicity and ease of use. SQLinq wont get in your way like other Data Access Layers will. SQLinq is not so much a Data Access Layer (DAL) as it is a code generation tool. Although, it’s not a code generator like others you may be used to. If you look at Entity Framework, you’ll se... [More]

SQL Azure: REBUILD All Indexes in Database – Alternative to DBCC DBREINDEX

Unfortunately there are some differences between SQL Server and SQL Azure. One of these differences is that SQL Azure does not support the “DBCC DBREINDEX” command. Thankfully there is an alternative you can use to rebuild the indexes within your SQL Azure databases. The alternative is to use “ALTER INDEX” instead. ALTER INDEX ALL ON TableName REBUILD Here’s an example that loops through all the tables in a database and rebuilds all their indexes: DECLARE @TableName... [More]