Check the Parameter Type of a Partition Function in SQL Server (T-SQL)

If you’ve got a partitioned table or index in SQL Server, and you want to check the parameter type of the partition function, you can use the sys.partition_parameters system catalog view.

This view returns a row for each parameter of a partition function.

The parameter type should match or be implicitly convertible to the data type of the partitioning column in the table or index.

Continue reading

2 Ways to Get Partition Information For a Table in SQL Server (T-SQL)

Here are a couple of ways to return partition info for a table in SQL Server.

  • You can use the sys.partitions system catalog view to return partition info for a table and most kinds of views.
  • You can use the sys.dm_db_partition_stats system dynamic management view to return page and row-count information for every partition in the current database.

If a table or index hasn’t been partitioned, these views will still return partition info (with a partition_number of 1). This is because all tables and indexes in SQL Server contain at least one partition, whether or not they are explicitly partitioned.

Continue reading

How to Import a JSON File into a SQL Server Table

If you have a JSON document, there are several ways you could go about getting it into SQL Server.

If it’s a small document, you could copy and paste its contents. If it’s a larger document (or even a small one), you might want to import the whole file.

This article presents an example of importing a JSON file into a SQL Server database.

Continue reading

How to Insert JSON into a Table in SQL Server

If you have a JSON document that you need to insert into a table in a SQL Server database, the OPENJSON() function could be just what you need.

OPENJSON() is a table-valued function that returns JSON in tabular format. That is, it converts your JSON into a tabular result set consisting of rows and columns. Therefore, it enables you to insert it into a table.

Continue reading

What is STATISTICS TIME in SQL Server?

In SQL Server, you can use the SET STATISTICS TIME statement to display the time it takes to execute a T-SQL statement.

More specifically, it returns the number of milliseconds required to parse, compile, and execute each statement.

When SET STATISTICS TIME is ON, the time statistics for a statement are displayed. When OFF, the time statistics are not displayed.

The setting of SET STATISTICS TIME is set at execute or run time and not at parse time.

Continue reading

SQL Server Error 113: Missing end comment mark ‘*/’

SQL Server error message 113 occurs when you omit a closing comment mark.

This can occur when you open a comment but forget to close it. It can also occur when you accidentally type an opening comment.

There may also be odd occasions where you get this error due to other factors, such as the way your SQL utility handles certain keywords etc.

Continue reading