If you were trying to create a SQL Server Agent job for the first time, but a message popped up that confused you, read on.
SQL Server
How to Enable the SQL Server Agent XPs using T-SQL
If you’re creating a SQL Server Agent job for the first time, you might find that you need to enable the SQL Server Agent extended stored procedures (SQL Server Agent XPs) first.
When you use the SQL Server Management Studio (SSMS) tool to start the SQL Server Agent service, these extended stored procedures are enabled automatically.
When you use T-SQL, you can enable the SQL Server Agent XPs with the sp_configure stored procedure.
SQL Server Error 206: Operand type clash
SQL Server error Msg 206, Level 16 is a common error to get when inserting data into a table.
It happens when you’re trying to insert data into a column that is incompatible with the data type you’re trying to insert.
This could happen if you accidentally try to insert data into the wrong column (or even the wrong table). But it could also happen if you incorrectly assume that SQL Server will convert the data for you.
To fix this issue, make sure you’re inserting the correct data type.
How to Map Multiple Partitions to a Single Filegroup in SQL Server (T-SQL)
If you’re familiar with creating partitioned tables in SQL Server, you might be used to creating a separate filegroup for each partition. This has its benefits, and may very well be the method you would choose in most scenarios.
However, you also have the option of mapping multiple partitions to a single filegroup.
In this article I share two examples of mapping multiple partitions to a single filegroup.
- Example 1 maps all partitions to a single filegroup.
- Example 2 maps some partitions to one filegroup, and some to another.
Find Out Which Partition a Given Value Would be Mapped to in SQL Server (T-SQL)
If you have a partitioned table or index in SQL Server, and you want to determine which partition a given value would be mapped to, you can do this nice and quickly with the $PARTITION system function.
All you need to know is the name of the partition function (and of course, the value you’re interested in).
How Implicit Transactions Work in SQL Server
There are four transaction modes in SQL Server. One of these is implicit mode.
In SQL Server, an implicit transaction is when a new transaction is implicitly started when the prior transaction completes, but each transaction is explicitly completed with a COMMIT or ROLLBACK statement.
This is not to be confused with autocommit mode, where the transaction is started and ended implicitly.
How to Fix “Conversion failed when converting the value to data type” in SQL Server
SQL Server error Msg 245, Level 16 tells us that there was a problem when trying to convert a value to a specific data type.
You’ll get this error if you try to insert the wrong data type into a column.
To fix this issue, make sure the data type of the value you’re trying to insert, matches the column’s type.
3 Ways to Return the Number of Rows in Each Partition in SQL Server (T-SQL)
If you’ve previously created a partitioned table in SQL Server, and you now want to know how many rows are being stored in each partition, here are three queries you can use.
In particular, you can:
- Query the
sys.dm_db_partition_statsview - Query the
sys.partitionsview - Use the
$PARTITIONfunction in a query
Below are examples of all three.
Execute a Trigger Only When Certain Columns are Updated (SQL Server)
SQL Server has the UPDATE() function that you can use within your DML triggers to check whether or not a specific column has been updated.
While this function only accepts one column, there’s nothing to stop you from including multiple UPDATE() clauses with AND or OR to test for multiple column updates.
Find Out if a Partition is Compressed in SQL Server (T-SQL)
In SQL Server, you can query the sys.partitions system catalog view to find out whether or not a partition has been compressed.
In particular, the data_compression column tells you whether it’s compressed or not. The data_compression_desc column tells you what type of compression it uses. If it isn’t compressed, it returns NONE.