Categories
SQL Server

The Cost of Convenience with the Import Data Wizard

If you need to create a copy of a table in another database, the ‘Import Data’ option may seem convenient. If you’ve used this method to copy to your dev environment and found things break, this post is for you. By letting the wizard create the destination table automatically, you might find your schema is […]

Categories
SQL

How Many Rows Are In That Table?

A question I ask myself often when exploring unfamiliar data sets. So here’s a quickie: If you’re in need of a quick measuring stick, this should do the job. Microsoft does note that the row_count field is an approximate value in this DMV. It’s taken from the internal table PARTITIONCOUNTS which can be cached, but […]

Categories
SQL

Adding NOT NULL Columns. Fast.

When adding a new column and wanting to default the value for existing records, it used to be a painful task. As of SQL Server 2012 that became much easier. But nobody told me, until Simon casually mentioned it in conversation recently. I had to see it for myself, so I thought I’d share for those who […]

Categories
SQL Server

Using External References with Data-Tier Applications

One method for transferring a database to a different environment is using a Data-Tier Application – in the form of a DACPAC (for schema) or BACPAC (for schema and data). Trying to use this approach with multi-database solutions is a challenge though as Data-Tier Applications don’t play nicely with cross-database objects. Let’s look at how we can […]

Categories
SQL

Revisiting Object Dependencies

Last week we looked at identifying object dependencies through performing a wildcard search on the objects such as procedures. I noted another option could be to use the views such as sys.sql_expression_dependencies and Kevin also commented about using the supporting functions such as sys.dm_sql_referencing_entities. I wanted to briefly look at both of these options and look at how their results can […]

Categories
SQL

Effectively Deploying Stored Procedure Changes

If writing code is the meat of our work then then packaging our stored procedures for deployment is the bread and butter to complete the sandwich. Deploying them is key so here we’ll be looking at options for how to effectively script those changes. The specific challenge we’re looking at here is how to change […]

Categories
SQL

Utilising Bit Masks with Bitwise Operators

A few weeks back we looked at options for storing multiple boolean flag values in a table. One of the options we considered was the use of a Bit Mask where we packed multiple flags into a single field. When we have individual fields within a table, using and manipulating those is straightforward. However when we’ve got […]

Categories
SQL

Schema Design for Bit Flags

When designing a data schema to store a variety of entities it can be common to require a selection of flags to be stored. There are different ways in which the data can be designed to accommodate this which I wanted to look at here. Examples of these fields could be an ‘Is Active’ flag […]

Categories
SQL Server

Object Visibility: Who Can See What

When developing database solutions we’ll typically spend some time considering security requirements, which will result (in part) with database roles being assigned to users or groups of users. Whilst security considerations will likely be focused on what folks can do in our databases, there’s a separate impact on what they can see in them too. I’ve had more than […]

Categories
SQL Server

Persisting Data Following Rollback

We recently looked at the impact of rolling back transactions on statistics and I thought it would be worth following this up to look at some other objects to see how they behave when a rollback occurs. When rolling back transactions we expect any changes to be rolled back. This isn’t always the case with data, just […]