千家信息网

创建原始数据库——创建数据、创建表

发表于:2025-01-21 作者:千家信息网编辑
千家信息网最后更新 2025年01月21日,书籍:数据库系统原理与设计(第3版)--万常选 廖国琼等编著任务驱动:由于找不到原始数据库,只有从零开始创建数据库、设计数据库关系图、输入数据,为后面深入研究数据库做好数据准备。数据库版本:SQL S
千家信息网最后更新 2025年01月21日创建原始数据库——创建数据、创建表

书籍:数据库系统原理与设计(第3版)--万常选 廖国琼等编著

任务驱动:由于找不到原始数据库,只有从零开始创建数据库、设计数据库关系图、输入数据,为后面深入研究数据库做好数据准备。

数据库版本:SQL Server 2005

操作步骤:

1.创建数据库源码如下或是通过数据库管理工具创建数据库

USE [master]

GO

/****** 对象: Database [ScoreDB] 脚本日期: 11/28/2018 21:44:34 ******/

CREATE DATABASE [ScoreDB] ON PRIMARY

( NAME = N'ScoreDB', FILENAME = N'D:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ScoreDB.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )

LOG ON

( NAME = N'ScoreDB_log', FILENAME = N'D:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\ScoreDB_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

COLLATE Chinese_PRC_CI_AS

GO

EXEC dbo.sp_dbcmptlevel @dbname=N'ScoreDB', @new_cmptlevel=90

GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))

begin

EXEC [ScoreDB].[dbo].[sp_fulltext_database] @action = 'disable'

end

GO

ALTER DATABASE [ScoreDB] SET ANSI_NULL_DEFAULT OFF

GO

ALTER DATABASE [ScoreDB] SET ANSI_NULLS OFF

GO

ALTER DATABASE [ScoreDB] SET ANSI_PADDING OFF

GO

ALTER DATABASE [ScoreDB] SET ANSI_WARNINGS OFF

GO

ALTER DATABASE [ScoreDB] SET ARITHABORT OFF

GO

ALTER DATABASE [ScoreDB] SET AUTO_CLOSE OFF

GO

ALTER DATABASE [ScoreDB] SET AUTO_CREATE_STATISTICS ON

GO

ALTER DATABASE [ScoreDB] SET AUTO_SHRINK OFF

GO

ALTER DATABASE [ScoreDB] SET AUTO_UPDATE_STATISTICS ON

GO

ALTER DATABASE [ScoreDB] SET CURSOR_CLOSE_ON_COMMIT OFF

GO

ALTER DATABASE [ScoreDB] SET CURSOR_DEFAULT GLOBAL

GO

ALTER DATABASE [ScoreDB] SET CONCAT_NULL_YIELDS_NULL OFF

GO

ALTER DATABASE [ScoreDB] SET NUMERIC_ROUNDABORT OFF

GO

ALTER DATABASE [ScoreDB] SET QUOTED_IDENTIFIER OFF

GO

ALTER DATABASE [ScoreDB] SET RECURSIVE_TRIGGERS OFF

GO

ALTER DATABASE [ScoreDB] SET ENABLE_BROKER

GO

ALTER DATABASE [ScoreDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF

GO

ALTER DATABASE [ScoreDB] SET DATE_CORRELATION_OPTIMIZATION OFF

GO

ALTER DATABASE [ScoreDB] SET TRUSTWORTHY OFF

GO

ALTER DATABASE [ScoreDB] SET ALLOW_SNAPSHOT_ISOLATION OFF

GO

ALTER DATABASE [ScoreDB] SET PARAMETERIZATION SIMPLE

GO

ALTER DATABASE [ScoreDB] SET READ_WRITE

GO

ALTER DATABASE [ScoreDB] SET RECOVERY FULL

GO

ALTER DATABASE [ScoreDB] SET MULTI_USER

GO

ALTER DATABASE [ScoreDB] SET PAGE_VERIFY CHECKSUM

GO

ALTER DATABASE [ScoreDB] SET DB_CHAINING OFF

2.创建表源码如下或是通过数据库管理工具创建表

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Class]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Class](

[classNo] [char](6) NOT NULL,

[className] [varchar](30) NULL,

[institute] [varchar](30) NULL,

[grade] [smallint] NULL,

[classNum] [tinyint] NULL,

CONSTRAINT [PK_Class] PRIMARY KEY CLUSTERED

(

[classNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 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].[Course]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Course](

[courseNo] [char](3) NOT NULL,

[courseName] [varchar](30) NULL,

[creditHour] [numeric](18, 0) NULL,

[courseHour] [int] NULL,

[priorCourse] [char](3) NULL,

CONSTRAINT [PK_Course] PRIMARY KEY CLUSTERED

(

[courseNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 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].[Term]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Term](

[termNo] [char](3) NOT NULL,

[termName] [varchar](30) NULL,

[remarks] [varchar](50) NULL,

CONSTRAINT [PK_Term] PRIMARY KEY CLUSTERED

(

[termNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 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].[Score]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Score](

[studentNo] [char](7) NOT NULL,

[courseNo] [char](3) NOT NULL,

[termNo] [char](3) NOT NULL,

[score] [numeric](18, 0) NULL,

CONSTRAINT [PK_Score] PRIMARY KEY CLUSTERED

(

[studentNo] ASC,

[courseNo] ASC,

[termNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) 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].[Student]') AND type in (N'U'))

BEGIN

CREATE TABLE [dbo].[Student](

[studentNo] [char](7) NOT NULL,

[studentName] [varchar](20) NULL,

[sex] [char](2) NULL,

[birthday] [datetime] NULL,

[native] [varchar](20) NULL,

[nation] [varchar](30) NULL,

[classNo] [char](6) NOT NULL,

CONSTRAINT [PK_Student_1] PRIMARY KEY CLUSTERED

(

[studentNo] ASC

)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

) ON [PRIMARY]

END

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Course_Course]') AND parent_object_id = OBJECT_ID(N'[dbo].[Course]'))

ALTER TABLE [dbo].[Course] WITH CHECK ADD CONSTRAINT [FK_Course_Course] FOREIGN KEY([priorCourse])

REFERENCES [dbo].[Course] ([courseNo])

GO

ALTER TABLE [dbo].[Course] CHECK CONSTRAINT [FK_Course_Course]

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Score_Course]') AND parent_object_id = OBJECT_ID(N'[dbo].[Score]'))

ALTER TABLE [dbo].[Score] WITH CHECK ADD CONSTRAINT [FK_Score_Course] FOREIGN KEY([courseNo])

REFERENCES [dbo].[Course] ([courseNo])

GO

ALTER TABLE [dbo].[Score] CHECK CONSTRAINT [FK_Score_Course]

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Score_Student]') AND parent_object_id = OBJECT_ID(N'[dbo].[Score]'))

ALTER TABLE [dbo].[Score] WITH CHECK ADD CONSTRAINT [FK_Score_Student] FOREIGN KEY([studentNo])

REFERENCES [dbo].[Student] ([studentNo])

GO

ALTER TABLE [dbo].[Score] CHECK CONSTRAINT [FK_Score_Student]

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Score_Term]') AND parent_object_id = OBJECT_ID(N'[dbo].[Score]'))

ALTER TABLE [dbo].[Score] WITH CHECK ADD CONSTRAINT [FK_Score_Term] FOREIGN KEY([termNo])

REFERENCES [dbo].[Term] ([termNo])

GO

ALTER TABLE [dbo].[Score] CHECK CONSTRAINT [FK_Score_Term]

GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Student_Class]') AND parent_object_id = OBJECT_ID(N'[dbo].[Student]'))

ALTER TABLE [dbo].[Student] WITH CHECK ADD CONSTRAINT [FK_Student_Class] FOREIGN KEY([classNo])

REFERENCES [dbo].[Class] ([classNo])

GO

ALTER TABLE [dbo].[Student] CHECK CONSTRAINT [FK_Student_Class]

3.设计数据库关系图

实战经验:建立主键与外键关系时,两者数据类型必须一致。

作者提供原始数据,请点击链接下载:http://down.51cto.com/data/2456174

数据 数据库 设计 原始 工具 源码 管理工具 管理 一致 书籍 任务 作者 原理 只有 实战 对象 日期 步骤 版本 类型 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 如何修改数据库中的数值 数据库名称怎样看 暗影国度朵丹尼尔服务器情况 手机网络安全云检测怎么关闭 如何提高网络安全发展 使用组策略管理服务器 stmp怎么打开服务器 网络安全预警管理体系认证申报 广州免费版进销存软件开发 ygopro2服务器 如何看数据库文件是否被调用 数据库技术根本目的 奉贤区网络技术服务承诺守信 部落冲突哪种服务器安全 网络安全的自我 门头沟区网络技术服务清单 网络安全最终是一个折衷方案 绩效考核软件开发部 数据库技术课程设计论文 北京微梦创科网络技术 类似运满满的软件开发 在网易版的服务器遇到有神装的人 交通银行雄安软件开发中心 中国多久开始研发6g网络技术 物理网络层网络安全对策 军事网络安全教育内容 c 手机软件开发工具 卫星地图 最新 数据库 胜卓网络技术有限公司 5月网络安全大检查
0