0

I need to generate script with description for each table and field. Filling Documentation tags puts comments to Objects, but not into the script. Is it possible to generate automaticly something like this:

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Field description' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SampleTable', @level2type=N'COLUMN',@level2name=N'SampleTableFieldName'
GO

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Description' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'SampleTable'
GO
7
  • 1
    I wonder if it can be done with T4? Might be worth investigating... in essence you want to enumerate the model and extract details to generate a code file. That is what T4 does? Commented Jul 8, 2011 at 11:40
  • Hi Smudge202! If I am not wrong, you advise to generate script manualy via T4 templates, but it will be better if exist any automatical way to pass table description from model to database... Commented Jul 8, 2011 at 12:45
  • In addition, how to get information about entities in the model? Something like summary or long description tag value... Commented Jul 8, 2011 at 12:48
  • 1
    I'm no expert with T4 but have worked with them in the past. My suggestion is to grab one of the existing T4 templates (such as the one for POCO entities) which you can download as an online template if you don't already have it. Have a look in that file (I recommend getting the Tangible T4 Editor VS Extension beforehand to make it readable). Have a look at how the template is working - it has object representations of every (I think) element in the underlying model. Using this you can automatically generate the SQL you need. Similarly, maybe do a search for existing T4 Templates? Commented Jul 8, 2011 at 13:04
  • This article doesn't do what you need it to do, but it does show the process of using T4 to work with the underlying model and should serve as a good platform to get started from. In essence, once you have created your template, the whole process of generating the SQL becomes automated, you simply open the file and run it. If you write the SQL defensively so as not to add records if they already exist, it'll simply be a case of running the SQL after you change the model. Hope it helps! Commented Jul 8, 2011 at 13:08

1 Answer 1

1

You could write a program that opens the edmx file as an xml document.

Then loop through the document outputing the commands to a text file.

Sign up to request clarification or add additional context in comments.

1 Comment

Cumbersome, but it's easiest solution at this time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.