Submitted by: Hannes du Preez(ojdupreez1978@gmail.com)

Thursday Mar 22nd 2018 by Hannes du Preez
Share:

Language: SQL, Expertise: Intermediate - Learn how to print all column definitions for all the tables in your database.

The following script can be used to print all column definitions for all the tables in your database.

SELECT

sys.schemas.name + '.' + sys.objects.name AS TableName,

sys.columns.name as ColumnName
,CASE
WHEN sys.types.name IN ('char','varchar') THEN sys.types.name+'('+CASE WHEN sys.columns.max_length<0 then="" max="" else="" convert="" varchar="" 10="" sys="" columns="" max_length="" end="" when="" types="" name="" in="" nvarchar="" nchar="" case="" 0="" 2="" numeric="" precision="" scale="" as="" datatype="" is_nullable="1" null="" not="" nullable="" from="" inner="" join="" t="" on="" system_type_id="sys.types.user_type_id" and="" is_user_defined="0" objects="" o="" object_id="sys.objects.object_id" schemas="" schema_id="sys.schemas.schema_id" where="" select="" table_name="" information_schema="" tables="" order="" by="" column_id="" code="">
Share:
Home
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved