SQL server 练习2的数据库 sql文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/weixin_37610397/article/details/79954913

  本篇博客用来存放SQL server 练习2的数据库,原本是sql文件来的。要还原的话,复制以下代码到sql文件中去然后执行即可。

USE [master]
GO
/****** Object:  Database [stuManage]    Script Date: 2018/4/15 23:06:28 ******/
CREATE DATABASE [stuManage]
 CONTAINMENT = NONE
 ON  PRIMARY 
( NAME = N'stuManage2', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\stuManage2.mdf' , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'stuManage2_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\stuManage2_log.ldf' , SIZE = 5184KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [stuManage] SET COMPATIBILITY_LEVEL = 90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [stuManage].[dbo].[sp_fulltext_database] @action = 'disable'
end
GO
ALTER DATABASE [stuManage] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [stuManage] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [stuManage] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [stuManage] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [stuManage] SET ARITHABORT OFF 
GO
ALTER DATABASE [stuManage] SET AUTO_CLOSE OFF 
GO
ALTER DATABASE [stuManage] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [stuManage] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [stuManage] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [stuManage] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [stuManage] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [stuManage] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [stuManage] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [stuManage] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [stuManage] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [stuManage] SET  DISABLE_BROKER 
GO
ALTER DATABASE [stuManage] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [stuManage] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [stuManage] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [stuManage] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [stuManage] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [stuManage] SET READ_COMMITTED_SNAPSHOT OFF 
GO
ALTER DATABASE [stuManage] SET HONOR_BROKER_PRIORITY OFF 
GO
ALTER DATABASE [stuManage] SET RECOVERY FULL 
GO
ALTER DATABASE [stuManage] SET  MULTI_USER 
GO
ALTER DATABASE [stuManage] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [stuManage] SET DB_CHAINING OFF 
GO
ALTER DATABASE [stuManage] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) 
GO
ALTER DATABASE [stuManage] SET TARGET_RECOVERY_TIME = 0 SECONDS 
GO
EXEC sys.sp_db_vardecimal_storage_format N'stuManage', N'ON'
GO
USE [stuManage]
GO
/****** Object:  Table [dbo].[course]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[course](
    [cNO] [char](6) NOT NULL,
    [cName] [char](40) NOT NULL,
    [cpNO] [char](6) NULL,
 CONSTRAINT [PK_course] PRIMARY KEY CLUSTERED 
(
    [cNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[course_class]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[course_class](
    [ccNO] [char](10) NOT NULL,
    [cNO] [char](6) NULL,
    [Term] [varchar](12) NULL,
    [tNO] [char](6) NULL,
    [CourseType] [varchar](10) NULL,
    [ExamType] [varchar](10) NULL,
    [Credit] [smallint] NULL,
    [Room] [varchar](20) NULL,
    [WeekTime] [varchar](20) NULL,
    [validity] [bit] NULL,
 CONSTRAINT [PK_course_class] PRIMARY KEY CLUSTERED 
(
    [ccNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[department]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[department](
    [dNO] [char](6) NOT NULL,
    [dName] [varchar](20) NULL,
    [dTel] [varchar](11) NULL,
 CONSTRAINT [PK_department] PRIMARY KEY CLUSTERED 
(
    [dNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[major]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[major](
    [mNO] [char](6) NOT NULL,
    [mName] [varchar](40) NULL,
    [mSubject] [varchar](40) NULL,
    [dNO] [char](6) NULL,
 CONSTRAINT [PK_major] PRIMARY KEY CLUSTERED 
(
    [mNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[student]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[student](
    [sNO] [varchar](10) NOT NULL,
    [sName] [varchar](20) NOT NULL,
    [mNO] [char](6) NOT NULL,
    [sSex] [char](4) NULL,
    [sBirth] [smalldatetime] NULL,
    [sNative] [varchar](20) NULL,
    [sHeight] [int] NULL,
    [sWeight] [int] NULL,
    [sEntime] [smalldatetime] NULL,
 CONSTRAINT [PK_student] PRIMARY KEY CLUSTERED 
(
    [sNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[student_course]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[student_course](
    [sNO] [varchar](10) NOT NULL,
    [ccNO] [char](10) NOT NULL,
    [NormalMark] [tinyint] NULL,
    [ExamMark] [tinyint] NULL,
    [Mark] [tinyint] NULL,
 CONSTRAINT [PK_student_course] PRIMARY KEY CLUSTERED 
(
    [sNO] ASC,
    [ccNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[teacher]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[teacher](
    [tNO] [char](6) NOT NULL,
    [tName] [varchar](20) NULL,
    [tSex] [char](4) NULL,
    [tBirth] [datetime] NULL,
    [tRank] [varchar](20) NULL,
    [tDegree] [char](6) NULL,
    [dNo] [char](6) NULL,
 CONSTRAINT [PK_teacher] PRIMARY KEY CLUSTERED 
(
    [tNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
/****** Object:  View [dbo].[mark_rank_view]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view  [dbo].[mark_rank_view] as
select top 10 student.sName,mark,'金融学' as '科目' from student,student_course,course_class,course 
where student.sNO = student_course.sNO
and student_course.ccNO = course_class.ccNo 
and course_class.cNo = course.cNo
and course.cName='金融学' 
order by mark desc ;
GO
/****** Object:  View [dbo].[student_mark_view]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[student_mark_view] as select sNo,sum(mark) as 总成绩,max(mark) as 最高成绩 from student_course group by sNo;

GO
/****** Object:  View [dbo].[three_course_view]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[three_course_view] 
as select  student.sName,course.cName from student,student_course,course_class,course
where student.sNO = student_course.sNO
and student_course.ccNO = course_class.ccNo 
and course_class.cNo = course.cNo;
GO
/****** Object:  View [dbo].[three_course_view_noExists]    Script Date: 2018/4/15 23:06:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create view [dbo].[three_course_view_noExists] 
as select  student.sName,course.cName from student,student_course,course_class,course
where student.sNO = student_course.sNO
and student_course.ccNO = course_class.ccNo 
and course_class.cNo = course.cNo;
GO
ALTER TABLE [dbo].[course_class]  WITH CHECK ADD  CONSTRAINT [FK_course_class_course] FOREIGN KEY([cNO])
REFERENCES [dbo].[course] ([cNO])
GO
ALTER TABLE [dbo].[course_class] CHECK CONSTRAINT [FK_course_class_course]
GO
ALTER TABLE [dbo].[course_class]  WITH CHECK ADD  CONSTRAINT [FK_course_class_teacher] FOREIGN KEY([tNO])
REFERENCES [dbo].[teacher] ([tNO])
GO
ALTER TABLE [dbo].[course_class] CHECK CONSTRAINT [FK_course_class_teacher]
GO
ALTER TABLE [dbo].[major]  WITH CHECK ADD  CONSTRAINT [FK_major_department] FOREIGN KEY([dNO])
REFERENCES [dbo].[department] ([dNO])
GO
ALTER TABLE [dbo].[major] CHECK CONSTRAINT [FK_major_department]
GO
ALTER TABLE [dbo].[student]  WITH CHECK ADD  CONSTRAINT [FK_student_major] FOREIGN KEY([mNO])
REFERENCES [dbo].[major] ([mNO])
GO
ALTER TABLE [dbo].[student] CHECK CONSTRAINT [FK_student_major]
GO
ALTER TABLE [dbo].[student_course]  WITH CHECK ADD  CONSTRAINT [FK_student_course_course_class] FOREIGN KEY([ccNO])
REFERENCES [dbo].[course_class] ([ccNO])
GO
ALTER TABLE [dbo].[student_course] CHECK CONSTRAINT [FK_student_course_course_class]
GO
ALTER TABLE [dbo].[teacher]  WITH CHECK ADD  CONSTRAINT [FK_teacher_department] FOREIGN KEY([dNo])
REFERENCES [dbo].[department] ([dNO])
GO
ALTER TABLE [dbo].[teacher] CHECK CONSTRAINT [FK_teacher_department]
GO
USE [master]
GO
ALTER DATABASE [stuManage] SET  READ_WRITE 
GO
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页