sql server - How do I extract a database schema using T-SQL? -


i'd extract xml schema database (a "database schema") using t-sql query in sql management studio, rather c# code. schema should include tables in database.

i can single table using following:

declare @schema xml set @schema = (select * student xml auto, elements, xmlschema('studentschema')) select @schema 

but how combine remaining tables? of tables related in way.

see this question, discusses how in code.

you alway use sp_msforeachtable , dynamic sql:

exec sp_msforeachtable ' declare @schema xml set @schema = (select * ? xml auto, elements, xmlschema(''?schema'')) select @schema ' 

you may have naming issue schema name since think have dbo. or schema prefix table name.


Comments

Popular posts from this blog

how to build hyperlink for query string in php -

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

queue - mq_receive: message too long -