帮助生成;使sql db genrater脚本有效 [英] help to genera;ize sql db genrater script

查看:112
本文介绍了帮助生成;使sql db genrater脚本有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个安装程序来自动在服务器上生成数据库和表.此应用程序仅适用于sql server.
我必须针对各种数据库(如oracle,db2等)归纳相同的应用程序.
我已经用c#编写了应用程序.
为此,我创建了一个文本文件,其中包含用于生成db及其表的脚本.我的问题是:从该文件中一一执行sql语句

以下是文件的内容
/***************************************************** ****************

 创建 数据库 [信息]
收集 SQL_Latin1_General_CP1_CI_AS
转到
使用 [信息]
转到
创建  [dbo].[员工](
[名称] [字符]( 30 )>收集 SQL_Latin1_General_CP1_CI_AS   NULL ,
[Rsvp] [ int ]  NULL ,
[请求] [ nvarchar ]( 4000 )>收集 SQL_Latin1_General_CP1_CI_AS  NULL 
)打开 [ PRIMARY ];

更改  [dbo].[员工] >还有   ADD 
 CONSTRAINT  [PK_Employees]  PRIMARY   KEY  集群
(
[姓名]
)打开 [ PRIMARY ]; 




****************************************************** *****************/
请同样帮我.

问候,
Amol

解决方案

如果要支持所有数据库,则需要使用严格的SQL并且没有特定功能.如果要在不同的数据库中使用不同的功能,则需要为每个数据库部署脚本.根本不在工厂范围内.在这里,您有一个实现,希望通过同一创建脚本将多个数据库作为目标-遗憾的是,您不能简单地做到这一点.

每个数据库供应商在创建数据库/表时都有其独特的风格.您需要做的是编写一个工厂类代码,该类分析某种形式的中间步骤,然后生成特定于数据库的代码.这是一项不平凡的任务.


Hi,

I have created a installer to generate database and tables on server automatically.This application works fine only with sql server.
I have to generalize the same application for various dbs like oracle,db2,etc.
I have written the application in c#.
for this i have create a text file which contains script for genrating db and its tables.My problem is:executing sql statement one by one from this file

following is the content of the file
/*****************************************************************

CREATE DATABASE [Info]
COLLATE SQL_Latin1_General_CP1_CI_AS
GO
USE [Info]
GO
CREATE TABLE [dbo].[Employees] (
[Name] [char] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Rsvp] [int] NULL ,
[Requests] [nvarchar] (4000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY];

ALTER TABLE [dbo].[Employees] WITH NOCHECK ADD
CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED
(
[Name]
) ON [PRIMARY];




*******************************************************************/
please help me for the same.

Regards,
Amol

解决方案

If you want to support all databases, then you need to use strict SQL and no specific features. If you want to use different features in different DBs, you need to deploy a script for each DB.


While .NET provides you with some great facilities with regards to Providers, there are some things that are simply outside the scope of the factories. Here you have an implementation that you want to target multiple databases from the same creation script - sorry to say that you can''t do this simply.

Each database vendor has their own unique flavour when it comes to creating databases/tables. What you would need to do is code a factory class that analyzed some form of intermediate step and then generated database specific code. This is a none-trivial task.


这篇关于帮助生成;使sql db genrater脚本有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆