Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to generate script of a database at run time in c#.
Posted
Updated 1-Jan-11 2:05am
v2

Also knowing what kind of database and driver you are using would be a big help.

Are you talking about generating the DDL that created an object within the database?

For example, I use oracle so I can call the database procedure

dbms_metadata.get_ddl(
object_type IN VARCHAR2,
name IN VARCHAR2,
schema IN VARCHAR2 DEFAULT NULL,
version IN VARCHAR2 DEFAULT 'COMPATIBLE',
model IN VARCHAR2 DEFAULT 'ORACLE',
transform IN VARCHAR2 DEFAULT 'DDL')
RETURN CLOB;

by using the select statement

SELECT DBMS_METADATA.GET_DDL('TABLE','SCHEMA','MY_TABLE') FROM DUAL;

You could then use this to output the sql for all your (schema) table objects by doing

SELECT DBMS_METADATA.GET_DDL('TABLE',TABLE_NAME) FROM USER_TABLES;

This is specific for Oracle though and would be different for sql server or mysql.
 
Share this answer
 
Build a string with DDL (Data definition language) SQL into a variable named strDDL.
Connect to your DB.
Instantiate SQL command c and set its Connection property.
Call c.ExecuteNonQuery(strDDL);
If you need to know what the exact syntax for the DDL of your specific DBMS is you'll have to consult the documentation of it.

Regards,
Manfred
 
Share this answer
 
If your database is MS SQLServer then this[^] article might help.
 
Share this answer
 
You should elaborate you question & be precise. for example Script of existing database, New database on installation etc.
 
Share this answer
 
Hi,

You can try the following link for MSSQL:http://msdn.microsoft.com/en-us/library/ms178078.aspx[^]

I hope it will help you..

Regards!
Aman
 
Share this answer
 
Comments
fjdiewornncalwe 2-Jan-11 10:32am    
His issue isn't the creation of the script, it is figuring out how to run it from C# code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900