| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2065 人关注过本帖
标题:如何执行SQL生成的语句
只看楼主 加入收藏
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
结帖率:100%
收藏
 问题点数:0 回复次数:7 
如何执行SQL生成的语句
以下是用SQL直接生成的语句:如何用C#执行???

USE [master]
GO
IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'mobile')
BEGIN
CREATE DATABASE [mobile] ON  PRIMARY
( NAME = N'mobile', FILENAME = N'E:\VS2005(C#)PC短信群发软件源代码\c_sms\SMS\SMS\DataBase\mobile.mdf' , SIZE = 6144KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON
( NAME = N'mobile_log', FILENAME = N'E:\VS2005(C#)PC短信群发软件源代码\c_sms\SMS\SMS\DataBase\mobile_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
END

GO
EXEC dbo.sp_dbcmptlevel @dbname=N'mobile', @new_cmptlevel=90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [mobile].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [mobile] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [mobile] SET ANSI_NULLS OFF
GO
ALTER DATABASE [mobile] SET ANSI_PADDING OFF
GO
ALTER DATABASE [mobile] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [mobile] SET ARITHABORT OFF
GO
ALTER DATABASE [mobile] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [mobile] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [mobile] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [mobile] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [mobile] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [mobile] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [mobile] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [mobile] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [mobile] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [mobile] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [mobile] SET  ENABLE_BROKER
GO
ALTER DATABASE [mobile] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [mobile] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [mobile] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [mobile] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [mobile] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [mobile] SET  READ_WRITE
GO
ALTER DATABASE [mobile] SET RECOVERY FULL
GO
ALTER DATABASE [mobile] SET  MULTI_USER
GO
ALTER DATABASE [mobile] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [mobile] SET DB_CHAINING OFF
USE [mobile]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_telsend]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tb_telsend](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [telnum] [varchar](50) NULL,
    [telcontent] [varchar](max) NULL,
    [teltime] [varchar](50) NULL,
 CONSTRAINT [PK_tb_telsend] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_tel]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tb_tel](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [username] [varchar](50) NULL,
    [usersex] [varchar](10) NULL,
    [usertel] [varchar](50) NULL,
 CONSTRAINT [PK_tb_tel] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[worker]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[worker](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [jh] [varchar](50) NULL,
    [shfzh] [varchar](50) NULL,
    [danwei] [varchar](50) NULL,
    [xm] [varchar](50) NULL,
    [sex] [varchar](2) NULL,
    [address] [varchar](200) NULL,
    [phone] [varchar](50) NULL,
    [dnt] [datetime] NULL,
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[times]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[times](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [lx] [varchar](50) NULL,
    [days] [varchar](50) NULL,
    [times] [varchar](50) NULL,
 CONSTRAINT [PK_times] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_admin]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tb_admin](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [adminusername] [varchar](50) NULL,
    [adminuserpwd] [varchar](50) NULL,
    [power] [nchar](1) NULL,
 CONSTRAINT [PK_tb_admin] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_note]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tb_note](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [type] [varchar](50) NULL,
    [note] [varchar](max) NULL,
 CONSTRAINT [PK_tb_note] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tb_resvice]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tb_resvice](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [smsnum] [varchar](50) NULL,
    [smscontent] [varchar](max) NULL,
 CONSTRAINT [PK_tb_resvice] PRIMARY KEY CLUSTERED
(
    [id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
搜索更多相关主题的帖子: SQL 语句 
2010-09-02 10:01
playermaker
Rank: 2
等 级:论坛游民
威 望:1
帖 子:87
专家分:17
注 册:2008-8-15
收藏
得分:0 
你要在哪里执行啊??
数据库里还是程序里?

数据库里用查询分析器执行

[url=http://www.]优联(Union)官方网站[/url]
2010-09-02 13:31
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
回复 2楼 playermaker
在C#程序中

http://www.
2010-09-02 15:47
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
???

http://www.
2010-09-03 16:55
Anne_Zhang
Rank: 2
等 级:论坛游民
威 望:1
帖 子:27
专家分:94
注 册:2010-4-10
收藏
得分:0 
你这个要在C#程序中执行的话,要把GO和END问的SQL语句都摘出来一步步执行喔,不可以一次全部把这些都执行
2010-09-04 16:36
makebest
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:3
帖 子:658
专家分:962
注 册:2005-3-17
收藏
得分:0 
如果可以的话, 应该就是 ExecuteNonQuery.
DbConnection cn;
DbCommand cmd = cn.CreateCommand();
= "sql";
cmd.ExecuteNonQuery();
2010-09-04 21:04
ycbbg
Rank: 1
来 自:江西
等 级:新手上路
帖 子:99
专家分:0
注 册:2007-11-26
收藏
得分:0 
我试过了,还是不能同时都执行,只能先执行创建数据库,再执行创建表!!还是要谢谢大家

http://www.
2010-09-06 17:23
何事惊慌
Rank: 6Rank: 6
等 级:侠之大者
威 望:4
帖 子:220
专家分:499
注 册:2008-7-2
收藏
得分:0 
你可以写出存储过程那样的形式的,那样是100%可以一下执行的啊

QQ:860234001
编程交流群:236949758
2010-09-10 22:25
快速回复:如何执行SQL生成的语句
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026609 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved