Skip to main content

Hiding user tables in SQL Management Studio

I spotted a question over at Stack Overflow asking whether it is possible to hide specific SQL Server user-tables from end users. Strictly speaking it is not, but there is a trick to get superfluous tables out of the way of the "Tables" node of the object explorer. While, on first glance, this may seem like poor practise, it turns out that there's a bona-fide case for it: Garbage tables used in table partitions.

A data warehouse that I recently delivered makes extensive use of SQL's partitioned tables feature - which enabled a data-load design which does incremental fast-loads... something which simply isn't possible without partitions.

The down-side of using partitions is that, in order to keep a fact table on-line whilst loading in new data, you effectively need three tables:

  1. The fact table
  2. A staging table, into which new data is loaded and prepared
  3. A garbage table into which the old partition of the fact table can be switched

The garbage table is of absolutely no value other than as a means for nuking a data partition, and so there's really very little value in cluttering Management Studio's Tables tree with these tables.

The answer? Mark the garbage tables as "database tools support" tables. This causes SSMS to hide the tables from normal view and instead list them under the "System Tables" node. Nice'n'neat!

Here's a script template which you can add to your template explorer:

EXEC sp_addextendedproperty
@name = N'microsoft_database_tools_support',
@value = '',
@level0type ='schema',
@level0name ='',
@level1type = 'table',
@level1name = N'.

<>'

Either add it to your template explorer, or simply paste into a query window, then press CTRL+SHIFT+M to launch the "specify values..." dialog.

Enjoy!

Comments

Popular posts from this blog

Reading Zip files in PowerQuery / M

Being a fan of PowerBI, I recently looked for a way to read zip files directly into the Data Model, and found this blog which showed a usable technique. Inspired by the possibilities revealed in Ken's solution, but frustrated by slow performance, I set out to learn the M language and write a faster alternative. UnzipContents The result of these efforts is an M function - UnzipContents - that you can paste into any PowerBI / PowerQuery report. It takes the contents of a ZIP file, and returns a list of files contained therein, along with their decompressed data: If you're not sure how to make this function available in your document, simply: Open up PowerQuery (either in Excel or in PowerBI) Create a new Blank Query. Open up the Advanced Editor  (found on the View tab in PowerBI). Copy-Paste the above code into the editor, then close the editor. In the properties window, rename the the function to  UnzipContents Usage Using the function is fairly straight for...

Power Query: Transforming YYYYMM dates (the quick way)

Accountants. Their unit of work seems to be the month, as if individual days don't exists, or don't count somehow. Nowhere is this better seen than in the notion of the accounting period , which all too often follows the form YYYYMM.  Try converting this directly into a date and Power Query starts making excuses faster than a kid with his hand caught in the cookie jar. The quick solution to this is to understand what Power Query's Table.TransformColumns does, and then leverage this knowledge to transform your YYYYMM values into proper date type columns. Table.TransformColumns As it's name suggests, this handy function allows you to convert the contents of a column from one type to another. The basic syntax is: = Table.TransformColumns( #"Your Source Table", { A list of tuples, specifying the columns and what functions to apply to each value} ) Lists {denoted by curly braces} are something you need to get comfortable with if you...

Validating RSA ID Numbers in SQL

In this post we’ll explore using SQLCLR integration to provide validation of South African Identity numbers – with the focus being slightly more on the ins and outs of CLR integration, than on how RSA ID numbers get validated. If you’re after the validation algorithm, look here . So what’s on the slab?... This solution makes RSA ID number validation possible by exposing a C# table valued function (TVF) to SQL server. The function takes an identity number as its input, and returns a single record with the following columns: IsValid                - bit: Whether the input identity number is valid. IsCitizen             - bit: Whether the number belongs to a South African citizen. Gender                - char: The gender of the individual - ‘M’ for male, ‘F’ for female. DateOfBirth        - date: The date of birth of the indivi...