In SQL Server, you can use sys.trigger_event_types
to return all events or event groups on which a trigger can fire.
Use CRYPT_GEN_RANDOM() to Create a Cryptographic, Random Number in SQL Server
In SQL Server, you can use the CRYPT_GEN_RANDOM()
function to return a cryptographic, randomly-generated number. The number is generated by the Cryptographic Application Programming Interface (CAPI).
CAPI is a Microsoft Windows platform specific application programming interface included with Microsoft Windows operating systems that provides services to enable developers to secure Windows-based applications using cryptography.
The CRYPT_GEN_RANDOM()
function accepts two arguments: the length (required), and a seed (optional).
The return value is varbinary(8000).
4 Ways to List All Views in a SQL Server Database
This article presents four ways to return a list of user-defined views in a SQL Server database.
If you want to see only system views, or both user-defined and system views, see Difference Between sys.views, sys.system_views, & sys.all_views in SQL Server.
2 Ways to Return a List of Triggers in a SQL Server Database using T-SQL
If you prefer to administer your SQL Server databases by running T-SQL queries, instead of using the GUI, here are two options for listing all triggers in the current database.
2 Ways to Return All User-Defined Functions in a SQL Server Database
This article presents two ways to return a list of user-defined functions in a SQL Server database.
Return the Base Data Type from a SQL_Variant Value in SQL Server
In SQL Server, you can use the SQL_VARIANT_PROPERTY()
function to return base data type information from a sql_variant value.
The function accepts two arguments: the sql_variant value, and the property for which information is to be provided.
Make an Object DIE in SQL Server
In SQL Server, if you try to drop an object that doesn’t exist, you’ll get an error. If you don’t want to get an error, you’ll need to add some extra code to check for the existence of the object.
Prior to SQL Server 2016, you needed to add an IF
statement that queried the relevant system objects to find out whether or not the object existed.
From SQL Server 2016, you can now use a new, cleaner method to check if an object exists. We’ll call it DROP IF EXISTS
(otherwise known as “DIE”).
Find Out What Operating System SQL Server is Running On (T-SQL Example)
When using SQL Server, you can use the sys.dm_os_host_info
system dynamic management view to return the operating system that SQL Server is running on.
This view includes a column called host_platform
which contains the type of operating system: Windows or Linux
LEFT() vs SUBSTRING() in SQL Server: What’s the Difference?
In SQL Server environments, two of the many string functions at our disposal are LEFT()
and SUBSTRING()
.
These functions do a similar thing, but there are differences. This article looks at some of the main differences between these functions.
LEFT() vs SET TEXTSIZE in SQL Server: What’s the Difference?
You may be familiar with the SET TEXTSIZE
statement in SQL Server, that enables you to limit the amount of data returned in a SELECT
query.
Perhaps you’re finding that its results are exactly the same as LEFT()
when running a specific query. Which begs the question: Is there a difference between these two options?