How to get the SQL View definition

09 November,2021 by Tom Collins

Question: I'm getting some errors in a BULK INSERT step - and I need to get the SQL View definition :  including the schema name , column_id , column name , data type , max length ,precision and collation name

Do you have a query where I can return the View column details?

 

Answer: 

select schema_name(v.schema_id) as schemaName,
       object_name(c.object_id) as viewName,
       c.column_id as columnID,
       c.name as columnName,
       type_name(user_type_id) as dataType,
       c.max_length as maxLength,
       c.precision,
	   c.collation_name as collationName
from sys.columns c
join sys.views v 
     on v.object_id = c.object_id
	 where object_name(c.object_id) = 'my_view_name'
order by viewName,
         column_id;



Read more on SQL Views

GRANT VIEW DEFINITION to script out tables


Author: Tom Collins (http://www.sqlserver-dba.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on How to get the SQL View definition


sqlserver-dba.com | SQL Server Performance Tuning | SQL Server DBA:Everything | FAQ | Contact|Copyright & Disclaimer