0

I'm currently working on a project which is responsible to generate database model based on its schema, I want to know is there any library in .Net which is able to parsing SQL Script file and allows me to:

  1. Get Database name from script

  2. Get Tables name

  3. Get each table's columns

  4. and anything you know for generating model

Any advice will be helpful.

3
  • 1
    "I'm currently working on a project which is responsible to generate database model based on its schema" - erm , VS 2008 and VS2010 already have this ability: Database Project. Failing that SMO... Commented Aug 21, 2011 at 8:23
  • My application is a web base application which will be hosted on none-dedicated server, So it can't access to database directly. I want each user able to upload the script file and download generated model. Commented Aug 21, 2011 at 8:29
  • 1
    You could look at Microsoft.Data.Schema.ScriptDom for parsing TSQL Scripts. Commented Aug 21, 2011 at 22:54

2 Answers 2

0

There isn't any library for this work except SMO. it is better that you have a query on sql system schemas. please see the below script as an example:

SELECT 
    SPECIFIC_NAME as SpName, 
    PARAMETER_NAME as ParameterName, 
    DATA_TYPE as DbType, 
    CHARACTER_MAXIMUM_LENGTH as Size  
 FROM INFORMATION_SCHEMA.PARAMETERS 
 WHERE PARAMETER_MODE = 'IN' OR PARAMETER_MODE = 'INOUT'

This script get the stored procedure parameters. or

SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('dbo.yourTableName')

for getting table columns. I recommend to you that don't use SMO.

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

4 Comments

What do you have against SMO? Can you clarify why you wouldn't use SMO??
I always have problem with new versions. it is my opinion.
@Mitch Wheat: I'm reading SMO overview, Is SMO able to do what requirements I posted ?
Yes. SMO has gotten a bad reputation in the past: most problems with it can be fic=xed. Might be of interest: mitch-wheat.blogspot.com/2011/07/…
0

There is more than I expected

ANTLR

SQLParser

Fantastic Tutorial-SQL Parser

Comments

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.