Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
How to generate script of a database at run time in c#.
Posted 31-Dec-10 18:46pm
Edited 1-Jan-11 2:05am
thatraja241.6K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You should elaborate you question & be precise. for example Script of existing database, New database on installation etc.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
Comments
Marcus Kramer at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

If your database is MS SQLServer then this[^] article might help.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 686
1 OriginalGriff 385
2 CPallini 240
3 PIEBALDconsult 150
4 Magic Wonder 131
0 OriginalGriff 5,795
1 Sergey Alexandrovich Kryukov 5,158
2 CPallini 4,740
3 George Jonsson 3,167
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 2 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100