存在于文本文件中的多条Sql语句如何一次性在aspx页面中执行,在线等待

wth668899 2007-02-25 12:43:42
在不借助SqlServer2000的工具的情况下,我如何将存在于my.sql文本文件中的多条sql语句在aspx页面中执行,该文本文件主要是创建表的语句和一些数据插入语句,我能够正确地连接到数据库,但是我需要通过aspx页面在数据库中创建所有的表,下面是My.sql文件中的一部分内容
--创建学生信息表
--学生信息表中的S_ID为“系别-年级-六位编码”,比如1993级采矿系王廷华的S_ID为CK-1993-199703
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[student_info]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[student_info]
GO

create table student_info
(
S_ID varchar(14) primary key,
S_Name varchar(20) not null,
S_iflogin bit,
Constraint S_ID_CHECK check(S_ID like '[A-Z][A-Z]-[0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]')
)
insert into student_info values('CK-1993-199703','王廷华',0)
insert into student_info values('CK-1993-199701','王立朝',0)
insert into student_info values('CK-1993-199702','陈江波',0)
insert into student_info values('CK-1993-199704','秦立论',0)
insert into student_info values('CK-1993-199705','林学历',0)
insert into student_info values('CK-1993-199706','陈伟',0)
insert into student_info values('CK-1993-199707','侯乐军',0)
insert into student_info values('CK-1993-199708','白冰',0)
insert into student_info values('CK-1993-199709','杨士朝',0)
insert into student_info values('CK-1993-199710','赵军',0)
insert into student_info values('CK-1993-199711','google',0)
GO
--========================================================================================
--创建学生注册表student_login
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[student_login]') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table [dbo].[student_login]
go


Create table student_login
(
S_ID varchar(14) primary key ,--学生学号
SL_Name varchar(20) unique not null,--学生注册笔名
SL_Pwd varchar(20) not null,--注册用的密码
SL_Date datetime default(getDate()),--注册时间,采用该行创建的时间
SL_MailBox varchar(30),--注册邮箱
SL_phone varchar(20),--注册电话
SL_Remark varchar(500),--备注
SL_ifclass bit,--是否选择班级
Foreign key(S_ID) references student_info(S_ID)

)
GO
--=========================================================================================
--创建班级学生表class_student
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[class_student]') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table [dbo].[class_student]
go

create table class_student
(
S_ID varchar(14) primary key,
class_id int,--班级序号
seat_id varchar(10),--作为序号
foreign key(S_ID) references student_info(S_ID)
)
GO
--=======================================================================================================
--创建通知信息表(Notice_info)
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[Notice_info]') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table [dbo].[Notice_info]
go

create table Notice_info
(
N_ID varchar(20) primary key,--通知序号
N_title varchar(100) not null,--通知标题
N_content varchar(5000) not null,--通知内容
Nu_date dateTime,--通知发布时间
Nu_student varchar(100) default 'All'--发布对象,默认所有
)
GO

--=======================================================================================================
--作业提交表(Exercise_update)
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[Exercise_update]') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table [dbo].[Exercise_update]
go

create Table Exercise_update
(
EU_ID varchar(20) not null,--作业序号
S_ID varchar(14) foreign key references student_info(S_ID),--学生学好
E_title varchar(100) not null,--作业标题
Eu_date datetime,--提交日期
constraint Exercise_update_pri primary key clustered--聚焦主键
(
EU_ID,S_ID
)

)
GO
--=======================================================================================================

--学生成绩表(stument_mark)
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[stument_mark]') and OBJECTPROPERTY(id,N'IsUserTable')=1)
drop table [dbo].[stument_mark]
go

create Table stument_mark
(
S_ID varchar(14) primary key,--学生学号
Lab1_mark numeric,--试验课1成绩
Lab2_mark numeric,--试验课2成绩
Lab3_mark numeric,--试验课3成绩
Lab4_mark numeric,--试验课4成绩
Lab5_mark numeric,--试验课5成绩
exercise_mark numeric,--作业成绩
Exam_mark numeric,--考试成绩
foreign key(S_ID) references student_info(S_ID)
)
GO

...全文
345 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Erison 2007-02-25
  • 打赏
  • 举报
回复
string infile=System.Web.HttpContext.Current.Server.MapPath("test.sql");
Process sqlprocess=new Process();
sqlprocess.StartInfo.FileName="osql.exe"; //sql的命令提示实用工具
sqlprocess.StartInfo.Arguments=String.Format("-U {0} -P {1} -S {2} -i {3}","sa","123456","192.168.0.28",@infile); //U为用户名,P为密码,S为目标服务器的ip,infile为数据库脚本所在的路径
sqlprocess.StartInfo.WindowStyle=ProcessWindowStyle.Hidden;
sqlprocess.Start();
sqlprocess.WaitForExit(); //等待程序执行.Sql脚本完毕
sqlprocess.Close();
Response.Write("<script>alert(’Ok.’);</script>");
executemylove 2007-02-25
  • 打赏
  • 举报
回复
up
feiyun0112 2007-02-25
  • 打赏
  • 举报
回复
读入string

判断go就用sqlcommand执行前面的string,再清空string,继续

*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)

http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
wth668899 2007-02-25
  • 打赏
  • 举报
回复
希望能的到您的解答
谢谢

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧