这几天帮学校数据库进行数据迁移,用我的笔记本进行迁移那叫个累啊
if exists (select * from sysobjects where name=newtable and xtype='U')
drop table newtable
go
SELECT dbo.student.studentid as '学号',
dbo.student.studentname as '姓名',
dbo.cclass.classname AS '班级',
dbo.XFZScore.acadyear as '学年',
dbo.XFZScore.term as '学期',
XFZClasscourse.ClassName as '课程名称',
dbo.XFZScore.zp1 as '总评成绩',
dbo.XFZStucourse.hcredic as '学分',
dbo.XFZStucourse.coursetype as '课程性质',
dbo.cspecialty.specname as '专业名称',
dbo.XFZScore.natureid as '学院名称',
dbo.cclass.gradeid as '年级',
dbo.XFZScore.zptype as'补考类型',
dbo.XFZScore.zpshow as '补考成绩'
into newtable
FROM dbo.student inner JOIN
dbo.cclass ON dbo.student.classid = dbo.cclass.classid
right JOIN
dbo.XFZScore ON dbo.student.indexid = dbo.XFZScore.indexid
inner JOIN
dbo.XFZClasscourse ON dbo.XFZScore.classid = dbo.XFZClasscourse.ClassId
left JOIN
dbo.XFZStucourse ON dbo.student.indexid = dbo.XFZStucourse.indexid
AND
dbo.XFZClasscourse.ClassId = dbo.XFZStucourse.classid
left JOIN
dbo.cspecialty ON dbo.cclass.specid = dbo.cspecialty.specid
left join
dbo.XFZCourseType on dbo.XFZStucourse.coursetype=dbo.XFZCourseType.Typename
ORDER BY dbo.cclass.classname,dbo.student.studentid,dbo.XFZScore.acadyear,dbo.XFZScore.term desc
go
alter table newtable add [id] int IDENTITY(1,1)
go
CREATE TABLE [newtable3] (
[id] [int] ,
[学号] [varchar] (30) ,
[姓名] [varchar] (50) ,
[班级] [varchar] (50) ,
[学年] [int] NULL ,
[学期] [varchar] (2) ,
[课程名称] [varchar] (50) ,
[总评成绩] [varchar] (10) ,
[学分] [real] NULL ,
[课程性质] [varchar] (30) ,
[专业名称] [varchar] (50) ,
[学院名称] [varchar] (30) ,
[年级] [varchar] (30) ,
[补考] [varchar] (20) ,
[重修] [varchar] (20)
)
go
delete from newtable3
declare
@id int,
@xh varchar(30),
@xm varchar(50),
@bj varchar(50),
@xn int,
@xq varchar(2),
@kcmc varchar(50),
@zpcj varchar(10),
@xf real,
@kcxz varchar(30),
@zymc varchar(50),
@xymc varchar(30),
@nj varchar(30),
@bklx int,
@bkcj varchar(20)
declare TT_cursor cursor for
select [id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考类型,补考成绩 from newtable
order by [id]
open TT_cursor
fetch next from TT_cursor
into
@id,
@xh ,
@xm ,
@bj ,
@xn ,
@xq ,
@kcmc ,
@zpcj ,
@xf,
@kcxz ,
@zymc ,
@xymc ,
@nj ,
@bklx ,
@bkcj
while @@FETCH_STATUS=0
begin
if @bklx=1
begin
insert into newtable3([id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考,重修)
values (@id,@xh ,@xm , @bj ,@xn ,@xq ,@kcmc , @zpcj , @xf,@kcxz , @zymc , @xymc , @nj,@bkcj,'')
end
else
if @bklx=2
begin
insert into newtable3([id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考,重修)
values (@id,@xh ,@xm , @bj ,@xn ,@xq ,@kcmc , @zpcj , @xf,@kcxz , @zymc , @xymc , @nj,'',@bkcj)
end
else
begin
insert into newtable3([id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考,重修)
values (@id,@xh ,@xm , @bj ,@xn ,@xq ,@kcmc , @zpcj , @xf,@kcxz , @zymc , @xymc , @nj,'','')
end
fetch next from TT_cursor
into
@id,
@xh ,
@xm ,
@bj ,
@xn ,
@xq ,
@kcmc ,
@zpcj ,
@xf,
@kcxz ,
@zymc ,
@xymc ,
@nj ,
@bklx ,
@bkcj
end
CLOSE TT_cursor
DEALLOCATE TT_cursor
drop table newtable
go
SELECT dbo.student.studentid as '学号',
dbo.student.studentname as '姓名',
dbo.cclass.classname AS '班级',
dbo.XFZScore.acadyear as '学年',
dbo.XFZScore.term as '学期',
XFZClasscourse.ClassName as '课程名称',
dbo.XFZScore.zp1 as '总评成绩',
dbo.XFZStucourse.hcredic as '学分',
dbo.XFZStucourse.coursetype as '课程性质',
dbo.cspecialty.specname as '专业名称',
dbo.XFZScore.natureid as '学院名称',
dbo.cclass.gradeid as '年级',
dbo.XFZScore.zptype as'补考类型',
dbo.XFZScore.zpshow as '补考成绩'
into newtable
FROM dbo.student inner JOIN
dbo.cclass ON dbo.student.classid = dbo.cclass.classid
right JOIN
dbo.XFZScore ON dbo.student.indexid = dbo.XFZScore.indexid
inner JOIN
dbo.XFZClasscourse ON dbo.XFZScore.classid = dbo.XFZClasscourse.ClassId
left JOIN
dbo.XFZStucourse ON dbo.student.indexid = dbo.XFZStucourse.indexid
AND
dbo.XFZClasscourse.ClassId = dbo.XFZStucourse.classid
left JOIN
dbo.cspecialty ON dbo.cclass.specid = dbo.cspecialty.specid
left join
dbo.XFZCourseType on dbo.XFZStucourse.coursetype=dbo.XFZCourseType.Typename
ORDER BY dbo.cclass.classname,dbo.student.studentid,dbo.XFZScore.acadyear,dbo.XFZScore.term desc
go
alter table newtable add [id] int IDENTITY(1,1)
go
CREATE TABLE [newtable3] (
[id] [int] ,
[学号] [varchar] (30) ,
[姓名] [varchar] (50) ,
[班级] [varchar] (50) ,
[学年] [int] NULL ,
[学期] [varchar] (2) ,
[课程名称] [varchar] (50) ,
[总评成绩] [varchar] (10) ,
[学分] [real] NULL ,
[课程性质] [varchar] (30) ,
[专业名称] [varchar] (50) ,
[学院名称] [varchar] (30) ,
[年级] [varchar] (30) ,
[补考] [varchar] (20) ,
[重修] [varchar] (20)
)
go
delete from newtable3
declare
@id int,
@xh varchar(30),
@xm varchar(50),
@bj varchar(50),
@xn int,
@xq varchar(2),
@kcmc varchar(50),
@zpcj varchar(10),
@xf real,
@kcxz varchar(30),
@zymc varchar(50),
@xymc varchar(30),
@nj varchar(30),
@bklx int,
@bkcj varchar(20)
declare TT_cursor cursor for
select [id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考类型,补考成绩 from newtable
order by [id]
open TT_cursor
fetch next from TT_cursor
into
@id,
@xh ,
@xm ,
@bj ,
@xn ,
@xq ,
@kcmc ,
@zpcj ,
@xf,
@kcxz ,
@zymc ,
@xymc ,
@nj ,
@bklx ,
@bkcj
while @@FETCH_STATUS=0
begin
if @bklx=1
begin
insert into newtable3([id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考,重修)
values (@id,@xh ,@xm , @bj ,@xn ,@xq ,@kcmc , @zpcj , @xf,@kcxz , @zymc , @xymc , @nj,@bkcj,'')
end
else
if @bklx=2
begin
insert into newtable3([id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考,重修)
values (@id,@xh ,@xm , @bj ,@xn ,@xq ,@kcmc , @zpcj , @xf,@kcxz , @zymc , @xymc , @nj,'',@bkcj)
end
else
begin
insert into newtable3([id],学号,姓名,班级,学年,学期,课程名称,总评成绩,
学分,课程性质,专业名称,学院名称,年级,补考,重修)
values (@id,@xh ,@xm , @bj ,@xn ,@xq ,@kcmc , @zpcj , @xf,@kcxz , @zymc , @xymc , @nj,'','')
end
fetch next from TT_cursor
into
@id,
@xh ,
@xm ,
@bj ,
@xn ,
@xq ,
@kcmc ,
@zpcj ,
@xf,
@kcxz ,
@zymc ,
@xymc ,
@nj ,
@bklx ,
@bkcj
end
CLOSE TT_cursor
DEALLOCATE TT_cursor
你们的每次考试成绩其实就是newtable3里的一条记录而已,哈哈。
它的重要性我不说你们也应该知道了吧。
所以说数据库是软件系统的核心,学好数据库(特别是语法)对你们将来的发展是很有帮助的。