question

Vinod Rao avatar image
Vinod Rao asked

Generate SQL DB Script using C#

Hi,

let me thank all the masters who have been sharing their knowledge and guiding the novice. Coming to the Question,
I have three tables at my backend
1) containing Table name, owner, schema(to me, its namespace) and other info
2) containing field name, table id, and other details like datatype, allow nulls etc.,
3) containing the relation name, field ids which are related

Now I need to create a generic SQLDBscript using the above 3 tables.
which should create DBscript for all the namespaces I defined in the above tables.
(In C#)

I hope I would get the more generic solution for my issue.

Thanks,
Vinod

sql-server-2008sql
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Matt Whitfield avatar image
Matt Whitfield answered

There isn't really a standard way of doing that - you really are talking about generating some scripts from your own custom data set, rather than scripting existing objects - and that pretty much ties you to writing your own code to do it.

It's not massively hard, but you will need to make sure that you script out all tables, then script out the foreign keys. This may well limit you somewhat (as it seems you have no facility for scripting of programmable elements, for instance), but it should do what you're asking for.

In terms of looking for ideas on how you might want to structure your code, you could look at one of the open source comparison projects, such as Open DBDiff.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.