You can use the @@DBTS
function to get the current rowversion of a given database in SQL Server. More specifically, it returns the last-used rowversion value of the current database.
What is “rowversion” in SQL Server?
In SQL Server, rowversion is a data type that exposes automatically generated, unique binary numbers within a database. It allows you to version-stamp table rows with a unique value. This helps maintain the integrity of the database when multiple users are updating rows at the same time.
Each SQL Server database has a a counter that is incremented for each insert or update operation that is performed on a table that contains a column with the rowversion data type (or its timestamp synonym, which is flagged for deprecation).
If a table contains a rowversion (or timestamp) column, any time a row is inserted or updated, the value of the rowversion column is set to the current rowversion value. This is true, even when an UPDATE
statement doesn’t result in any changes to the data.
4 Data Types to be Deprecated in SQL Server
As of SQL Server 2017 (and SQL Server 2019 preview), four data types are flagged for deprecation in a future version of SQL Server.
They are:
- timestamp
- text
- ntext
- image
Microsoft advises that these data types are currently in maintenance mode and they will be removed in a future version of SQL Server. This means you should avoid using these data types in new development work, and you should plan to modify applications that currently use them.
Find Dependencies in SQL Server: sql_expression_dependencies
In SQL Server, you can use the sys.sql_expression_dependencies
system catalog view to return all dependencies on a user-defined entity in the current database. This includes dependences between natively compiled, scalar user-defined functions and other SQL Server modules.
You can use this view to:
- Return entities that depend on a given entity
- Return entities on which a given entity depends
So for example, you could use it to return all objects that reference a specific table. You could also use it to return all objects that a specific stored procedure references within its code.
Continue readingExample of SQL Server’s sys.dm_sql_referenced_entities() Returning an Entity that References a Linked Server
One of the things about the sys.dm_sql_referenced_entities()
system dynamic management function is that you can use it on cross-database and cross-server entities.
This means you can find referenced entities that are in a different database and even on a different server.
This article provides an example of sys.dm_sql_referenced_entities()
returning a stored procedure that queries a database on a linked server.
Find Referenced Entities in SQL Server: sys.dm_sql_referenced_entities
In SQL Server, you can use the sys.dm_sql_referenced_entities()
system dynamic management function to get a list of all user-defined entities that are referenced by name, in the definition of a given entity.
In other words, it returns a list of all user-defined entities that a specific entity depends on.
Continue readingFind Referencing Entities in SQL Server: sys.dm_sql_referencing_entities()
In SQL Server, you can use the sys.dm_sql_referencing_entities()
system dynamic management function to get a list of all entities in the current database that reference another user-defined entity by name.
In other words, it returns a list of entities that depend on the given entity.
Continue readingReturn a List of Tables & Views in SQL Server using T-SQL (sp_tables)
In SQL Server, you can use the sp_tables
system stored procedure to get a list of tables and views in the current environment.
You can return all tables and views, or you can narrow it down to a particular owner, type, pattern, or even a specific table or view.
Quickest Way to List All Databases in SQL Server using T-SQL
If you’re using SQL Server via a command line interface, you probably don’t see a persistent list of databases like you normally would while using a GUI (such as SSMS or Azure Data Studio).
In such cases, you can use the sp_databases
system stored procedure to return a list of databases. This stored procedure specifically lists databases that either reside in an instance of the SQL Server or are accessible through a database gateway.
This is probably the quickest and easiest way of listing all databases using T-SQL. You can simply type sp_databases
for a list of databases, or to be more explicit, EXEC sp_databases
.
Get Column Info for a Table or View in SQL Server (T-SQL: sp_columns)
In SQL Server you can use the sp_columns
system stored procedure to return column information for the specified objects that can be queried in the current environment. Such a objects include tables, views, or other objects that have columns such as table-valued functions.
You can get information for a specific column, or you can specify all columns from a given table, view, etc.