Here are seven ways to check what version of MySQL you’re running.
Continue readingTag: how to
Fix Msg 3728 in SQL Server “… is not a constraint”
If you’re getting an error that reads something like “Msg 3728, Level 16, State 1, Line 1
‘DF__Dogs__DogId__6FE99F9F’ is not a constraint“, it’s probably because you’re trying to drop a constraint that isn’t in the database.
To fix this issue, check to make sure the constraint exists before dropping it. Alternatively, use the IF EXISTS
clause to drop the constraint only if it exists.
Fix “ERR wrong number of arguments for ‘hrandfield’ command” in Redis
If you’re getting an error that reads “ERR wrong number of arguments for ‘hrandfield’ command“, it’s probably because you’re not passing any arguments when using the HRANDFIELD
command.
The HRANDFIELD
command requires at least one argument, and accepts up to three arguments (at the time of writing).
How to Create a Repeating Sequence in SQL Server
When we create a sequence object in SQL Server, we have the option of making it a repeating sequence or a nonrepeating sequence. By repeating I mean, we can have the sequence continually start again once the min/max value has been reached. In other words, we can have the sequence reiterate over and over again.
We can do this with the CYCLE
argument.
Fix “WRONGTYPE Operation against a key holding the wrong kind of value” when Setting a Hash in Redis
If you get an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when setting a hash with a command like HSET
or HSETNX
, it’s probably because you’re trying to set a non-hash key that already exists. In other words, the key already exists, but it doesn’t contain a hash.
To fix this issue, be sure to use these commands on keys that either don’t already exist, or contain a hash.
Continue readingHow to Set Up Named Time Zones in MySQL
If you want to use named time zones in MySQL, you’ll need to make sure they’ve been configured.
By “named time zones”, I mean being able to use strings like US/Eastern
instead of −04:00
or −05:00
when specifying the time zone. For example, when using the CONVERT_TZ()
function.
Here’s how to configure named time zones in MySQL.
Continue readingFix ERROR 1045: “Access denied for user…” in MySQL
If you’re getting error 1045 that reads something like “Access denied for user ‘root’@’localhost’“, it’s because you’re trying to log in to MySQL without the right credentials.
This usually happens when we provide the wrong password. But there could also be another cause. For example, we could be trying to do something as the root
user that requires a password, but the root
user hasn’t yet had its password set.
To fix this issue, be sure to provide the correct password when connecting to MySQL.
Continue readingHow to Include Elements that Contain NULL Values When Using FOR XML in SQL Server
When using FOR XML
in SQL Server, we can use the ELEMENTS
directive to include a column as an element instead of an attribute. However by default, if a column contains a NULL value, no element is produced for that column in the resulting XML document. This may or may not be what we want, depending on the requirements.
If we want such columns to be included in the XML even when they contain NULL values, all we need to do is include the XSINIL
option. This option specifies that any column that has a NULL value automatically gets an element with xsi:nil="true"
in the resulting XML.
The alternative is ABSENT
, which means columns with NULL values are excluded (this is the default behaviour).
How to Include Elements that Contain NULL Values When Using FOR XML EXPLICIT in SQL Server
When using FOR XML EXPLICIT
in SQL Server, we can use the ELEMENT
directive to include a column as an element instead of an attribute. However, this directive doesn’t allow for NULL values. What I mean is that if a column contains a NULL value, no element is produced for that column in the resulting XML document. This may or may not be what we want, depending on the requirements.
If we want such columns to be included in the XML even when they contain NULL values, we can use the ELEMENTXSINIL
directive instead of ELEMENT
.
Convert a Number to a Date in SQL Server
Trying to convert a number to a date in SQL Server can be tricky and may not always work. It all depends on the number and what exactly it is that we’re trying to do. That said, here are some scenarios where we can convert a number to a date value.
Continue reading