Including Tables & Schemas when Listing the Identity Columns in a SQL Server Database

If you’ve ever queried the sys.identity_columns view in SQL Server, you’ll know that it returns a list of identity columns. It also returns the object_id of the table, but not the table name or its schema.

You can use the code examples in this article to return the identity columns, along with their respective tables and schemas.

Continue reading

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).

Continue reading