Skip to main content
Solved

Can I import VIEWS along with tables from my database?


Andrew.Alten

I would like to be able to import a couple views into my ERD import section or into my saved shapes section. Is there a good way to do this?

 

Thanks

Best answer by Brant G

Not perfect but this may help. They'll show as tables

 

SELECT 'sqlserver' as dbms
db_name() as TABLE_CATALOG
schema_name(v.schema_id) as TABLE_SCHEMA
object_name(c.object_id) as TABLE_NAME
c.name as COLUMN_NAME
c.column_id as ORDINAL_POSITION
type_name(user_type_id) as data_type
case charindex('char'type_name(user_type_id))
when 0 then null
else c.max_length end as CHARACTER_MAXIMUM_LENGTH
NULL as CONSTRAINT_TYPE
NULL as TABLE_SCHEMA
NULL as TABLE_NAME
NULL as COLUMN_NAME
FROM sys.columns c
JOIN sys.views v on v.object_id = c.object_id
ORDER BY schema_name(v.schema_id)
object_name(c.object_id)
column_id

View original
Did this topic help you find an answer to your question?

Remy M
  • Lucidite
  • March 23, 2018

Hi Andrew

Thanks for your post. Unfortunately there is no way to do this with ERD import at this time. I recommend posting in our product feedback space as this is the best way for our product team to hear your feedback on this.


Brant G
  • September 23, 2019

Not perfect but this may help. They'll show as tables

 

SELECT 'sqlserver' as dbms
db_name() as TABLE_CATALOG
schema_name(v.schema_id) as TABLE_SCHEMA
object_name(c.object_id) as TABLE_NAME
c.name as COLUMN_NAME
c.column_id as ORDINAL_POSITION
type_name(user_type_id) as data_type
case charindex('char'type_name(user_type_id))
when 0 then null
else c.max_length end as CHARACTER_MAXIMUM_LENGTH
NULL as CONSTRAINT_TYPE
NULL as TABLE_SCHEMA
NULL as TABLE_NAME
NULL as COLUMN_NAME
FROM sys.columns c
JOIN sys.views v on v.object_id = c.object_id
ORDER BY schema_name(v.schema_id)
object_name(c.object_id)
column_id


Reply