本文介绍了生成数据库脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在运行时在c#中生成数据库脚本.
How to generate script of a database at run time in c#.
推荐答案另外,知道您使用的是哪种数据库和驱动程序也会有很大帮助. 您是在谈论生成在数据库中创建对象的DDL吗? 例如,我使用oracle,因此可以调用数据库过程 dbms_metadata.get_ddl( object_type IN VARCHAR2, 名称为VARCHAR2, VARCHAR2 DEFAULT NULL中的架构, 版本VARCHAR2默认为兼容", 型号为VARCHAR2 DEFAULT``ORACLE'', 转换IN VARCHAR2 DEFAULT``DDL'') 返回CLOB; 通过使用select语句 从DUAL选择SELECT DBMS_METADATA.GET_DDL(``TABLE'',``SCHEMA'',``MY_TABLE''); 然后,您可以使用此代码通过执行为所有(模式)表对象输出sql. 从USER_TABLES中选择DBMS_METADATA.GET_DDL(``TABLE'',TABLE_NAME); 但是,这是特定于Oracle的,对于sql server或mysql来说会有所不同. 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.
使用DDL(数据定义语言)SQL将字符串构建到名为strDDL的变量中. 连接到您的数据库. 实例化SQL命令c并设置其Connection属性. 呼叫c.ExecuteNonQuery(strDDL); 如果您需要了解特定DBMS的DDL的确切语法是什么,则必须查阅该文档的文档. 问候, Manfred 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
如果您的数据库是MS SQLServer,则此 [ ^ ]文章可能会有所帮助. If your database is MS SQLServer then this[^] article might help.
更多推荐
生成数据库脚本
发布评论