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

标签: sql
13人阅读 评论(0) 收藏 举报
分类:

  本篇博客用来存放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
查看评论

数据库 SQL Server中级

-
  • 1970年01月01日 08:00

sql基础经典练习题(.sql文件可直接运行)

  • 2013年05月29日 15:42
  • 13KB
  • 下载

SQl练习脚本

  • 2014年04月01日 15:43
  • 4KB
  • 下载

SQL Server导入大的sql脚本

如需转载请标明出处:http://blog.csdn.net/itas109 QQ技术交流群:129518033 SQL Server导入大的sql脚本的时候可能报如下错误: 未能完成操作。存储空...
  • itas109
  • itas109
  • 2015-11-17 15:48:20
  • 5050

SQL server 数据库练习工具

  • 2013年05月22日 14:58
  • 100KB
  • 下载

sql server 2005导入超大sql脚本文件

1. SQL server2008 导入超大SQL脚本文件(超过10);   2. 采用SQLManagement 查询工具不能打开,所以使用osql在doc命令下执行;     3. os...
  • sun_wangdong
  • sun_wangdong
  • 2015-05-26 09:54:35
  • 3638

sqlserver2012导入sql大文件

osql -S 192.168.1.112 -U sa -P 123456 -i D:\1.sql ,-S 服务器名 -U 用户名 -P 密码 -i 文件地址,等待执行完毕即可以上在sql2012下执...
  • qq_36617310
  • qq_36617310
  • 2018-03-23 10:30:01
  • 68

使用Sql Server Management Studio 2008将数据导出到Sql文件中

转自:http://www.cnblogs.com/greenerycn/archive/2010/04/09/SqlServer2008GenerateDataScript.html 最近...
  • suyu_yuan
  • suyu_yuan
  • 2016-09-30 11:23:44
  • 865

很全的sql语句练习题(+sql脚本文件)

欢迎使用Markdown编辑器写博客本Markdown编辑器使用StackEdit修改而来,用它写博客,将会带来全新的体验哦: Markdown和扩展Markdown简洁的语法 代码块高亮 图片链接和...
  • qq_22075041
  • qq_22075041
  • 2017-04-02 17:42:36
  • 8701

利用PHP执行SQL文件,将SQL文件导入到数据库

来源:http://www.php100.com/html/dujia/2015/0919/8973.html [导读] 如何利用php自动执行 sql文件。其实很简单,就是获取sql文件中的内...
  • gb4215287
  • gb4215287
  • 2016-02-04 17:52:14
  • 250
    个人资料
    持之以恒
    等级:
    访问量: 1001
    积分: 211
    排名: 36万+
    文章存档