sqlserver.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 17 Feb 2024 23:00:15 +0200
changeset 2587 0230a6677c40
parent 2560 e023a7bbaf3b
permissions -rw-r--r--
Video Speed Class


============
 SQL Server
============
.. contents::
   :local:

Informational schema
====================

::

  SELECT * FROM sys.tables;
  SELECT * FROM sys.views;
  SELECT * FROM sys.indexes;
  SELECT * FROM sys.types;

  SELECT * FROM information_schema.tables;

Table stats
===========

Individual table::

  EXEC sp_spaceused NAME;

All tables in a schema::

  sp_msforeachtable 'EXEC sp_spaceused [?]';

List collations
===============

::

  SELECT name, description FROM sys.fn_helpcollations();

Finding expression type
=======================

::

  SELECT SQL_VARIANT_PROPERTY(current_timestamp, 'BaseType');
  SELECT SQL_VARIANT_PROPERTY(current_timestamp, 'Precision');
  SELECT SQL_VARIANT_PROPERTY(current_timestamp, 'Scale');
  SELECT SQL_VARIANT_PROPERTY(current_timestamp, 'MaxLength');

Number of bytes required to hold both the metadata and data of the value::

  SELECT SQL_VARIANT_PROPERTY(current_timestamp, 'TotalBytes');

https://learn.microsoft.com/en-us/sql/t-sql/functions/sql-variant-property-transact-sql
  SQL_VARIANT_PROPERTY (Transact-SQL).