The following queries demonstrate the T-SQL SUBSTRING function. I've also included a comparison with the C# function of the same name. Unlike C#, the T-SQL SUBSTRING is 1 based. [code language="sql"] print substring('a,b,c,d', 1, 1); -- RETURNS: a [/code] Unlike C#, SUBSTRING's 3rd parameter is NOT optional. You can't leave it blank if you want … Continue reading T-SQL Review: SUBSTRING
Category: Scripts
Welcome to my personal collection of Transact-SQL queries and scripts. This stuff was collected over the span of many years, but everything I’ve posted here has been tested on the stated version of SQL Server. Of course, your mileage may vary.
Return DDL from METADATA
Tested on server version: SQL Server 2016 Developer Edition Reference info accurate on: January, 2018 The following script demonstrates how to generate each column's DDL from metadata in Transact-SQL. Example Output: T-SQL [code language="sql"] DECLARE @rundate datetime2 = getdate(); DECLARE @default_collation nvarchar(128); -- = 'SQL_Latin1_General_CP1_CI_AS'; SELECT @default_collation = convert(sysname, serverproperty('collation')) SELECT TABLE_CATALOG ,TABLE_SCHEMA ,TABLE_NAME ,COLUMN_NAME … Continue reading Return DDL from METADATA
Return all System Object Definitions (DDL)
Tested on server version: SQL Server 2016 Developer Edition Reference info accurate on: January, 2018 The following view returns a comprehensive list of all System Objects on a server. It returns the object name, with and without concatinating the schema to the name. The view can be created and executed as-is.