执行SQL数据库脚本
我们接下来要执行下面的SQL,为了后面使用EntityFramework Core数据库上下文对象用。
一、可以复制下图的SQL脚本到SQL Server中执行:
也可以直接点击链接下载SQL脚本运行(包括其他脚本素材):下载素材
USE [master] GO /****** Object: Database [shoppingTestDB] Script Date: 2023/1/2 21:23:00 ******/ CREATE DATABASE [shoppingTestDB] CONTAINMENT = NONE ON PRIMARY ( NAME = N'shoppingTestDB', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\shoppingTestDB.mdf' , SIZE = 8192KB , MAXSIZE = UNLIMITED, FILEGROWTH = 65536KB ) LOG ON ( NAME = N'shoppingTestDB_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\shoppingTestDB_log.ldf' , SIZE = 8192KB , MAXSIZE = 2048GB , FILEGROWTH = 65536KB ) GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin EXEC [shoppingTestDB].[dbo].[sp_fulltext_database] @action = 'enable' end GO ALTER DATABASE [shoppingTestDB] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [shoppingTestDB] SET ANSI_NULLS OFF GO ALTER DATABASE [shoppingTestDB] SET ANSI_PADDING OFF GO ALTER DATABASE [shoppingTestDB] SET ANSI_WARNINGS OFF GO ALTER DATABASE [shoppingTestDB] SET ARITHABORT OFF GO ALTER DATABASE [shoppingTestDB] SET AUTO_CLOSE OFF GO ALTER DATABASE [shoppingTestDB] SET AUTO_SHRINK OFF GO ALTER DATABASE [shoppingTestDB] SET AUTO_UPDATE_STATISTICS ON GO ALTER DATABASE [shoppingTestDB] SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTER DATABASE [shoppingTestDB] SET CURSOR_DEFAULT GLOBAL GO ALTER DATABASE [shoppingTestDB] SET CONCAT_NULL_YIELDS_NULL OFF GO ALTER DATABASE [shoppingTestDB] SET NUMERIC_ROUNDABORT OFF GO ALTER DATABASE [shoppingTestDB] SET QUOTED_IDENTIFIER OFF GO ALTER DATABASE [shoppingTestDB] SET RECURSIVE_TRIGGERS OFF GO ALTER DATABASE [shoppingTestDB] SET DISABLE_BROKER GO ALTER DATABASE [shoppingTestDB] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTER DATABASE [shoppingTestDB] SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTER DATABASE [shoppingTestDB] SET TRUSTWORTHY OFF GO ALTER DATABASE [shoppingTestDB] SET ALLOW_SNAPSHOT_ISOLATION OFF GO ALTER DATABASE [shoppingTestDB] SET PARAMETERIZATION SIMPLE GO ALTER DATABASE [shoppingTestDB] SET READ_COMMITTED_SNAPSHOT OFF GO ALTER DATABASE [shoppingTestDB] SET HONOR_BROKER_PRIORITY OFF GO ALTER DATABASE [shoppingTestDB] SET RECOVERY FULL GO ALTER DATABASE [shoppingTestDB] SET MULTI_USER GO ALTER DATABASE [shoppingTestDB] SET PAGE_VERIFY CHECKSUM GO ALTER DATABASE [shoppingTestDB] SET DB_CHAINING OFF GO ALTER DATABASE [shoppingTestDB] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) GO ALTER DATABASE [shoppingTestDB] SET TARGET_RECOVERY_TIME = 60 SECONDS GO EXEC sys.sp_db_vardecimal_storage_format N'shoppingTestDB', N'ON' GO USE [shoppingTestDB] GO /****** Object: Table [dbo].[category] Script Date: 2023/1/2 21:23:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[category]( [id] [int] IDENTITY(1,1) NOT NULL, [catename] [varchar](50) NULL, CONSTRAINT [PK_category] PRIMARY KEY CLUSTERED ( [id] 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 /****** Object: Table [dbo].[goods] Script Date: 2023/1/2 21:23:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[goods]( [id] [int] IDENTITY(1,1) NOT NULL, [title] [varchar](50) NULL, [price] [decimal](8, 2) NULL, [number] [int] NULL, [introduce] [varchar](50) NULL, CONSTRAINT [PK_goods] PRIMARY KEY CLUSTERED ( [id] 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 /****** Object: Table [dbo].[login] Script Date: 2023/1/2 21:23:00 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[login]( [id] [int] IDENTITY(1,1) NOT NULL, [username] [varchar](50) NULL, [pwd] [varchar](50) NULL, [nickname] [varchar](50) NULL, [age] [int] NULL, [state] [smallint] NULL, CONSTRAINT [PK_login] PRIMARY KEY CLUSTERED ( [id] 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 IDENTITY_INSERT [dbo].[category] ON INSERT [dbo].[category] ([id], [catename]) VALUES (1, N'母嬰用品') INSERT [dbo].[category] ([id], [catename]) VALUES (2, N'食品') INSERT [dbo].[category] ([id], [catename]) VALUES (3, N'牛奶') INSERT [dbo].[category] ([id], [catename]) VALUES (4, N'其他') INSERT [dbo].[category] ([id], [catename]) VALUES (5, N'数码') SET IDENTITY_INSERT [dbo].[category] OFF GO SET IDENTITY_INSERT [dbo].[goods] ON INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (1, N'辣条', CAST(20.00 AS Decimal(8, 2)), 10, N'好吃辣条') INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (2, N'饼干', CAST(10.00 AS Decimal(8, 2)), 100, N'饼干') INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (3, N'西瓜', CAST(30.00 AS Decimal(8, 2)), 100, N'西瓜霜') INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (4, N'笔', CAST(1.00 AS Decimal(8, 2)), 100, N'笔') INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (5, N'闹钟', CAST(22.00 AS Decimal(8, 2)), 111, N'闹钟') INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (6, N'书', CAST(10.00 AS Decimal(8, 2)), 111, N'书本') INSERT [dbo].[goods] ([id], [title], [price], [number], [introduce]) VALUES (7, N'西瓜霜', CAST(1.00 AS Decimal(8, 2)), 222, N'药品') SET IDENTITY_INSERT [dbo].[goods] OFF GO SET IDENTITY_INSERT [dbo].[login] ON INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (2, N'123', N'123', N'李四', 40, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (5, N'123111', N'123511', N'李四211', 3332, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (6, N'1232', N'1234', N'李四3', 23, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (8, N'123411', N'123311', N'李四21', 35, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (11, N'1234', N'1233', N'李四2', 25, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (12, N'1234', N'1233', N'李四2', 25, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (13, N'1234', N'1233', N'李四2', 25, 1) INSERT [dbo].[login] ([id], [username], [pwd], [nickname], [age], [state]) VALUES (14, N'1234', N'1233', N'李四2', 25, 1) SET IDENTITY_INSERT [dbo].[login] OFF GO USE [master] GO ALTER DATABASE [shoppingTestDB] SET READ_WRITE GO
二、在SSM执行SQL脚本
复制该SQL脚本或者是下载该SQL,使用SSM打开该脚本,然后点击运行。
如果执行过程中报错,请观看村长的这个视频教学导入:SQL的三种备份方法
执行后,可以看到下图结果,左侧有对应的数据库shopTestDB,这样就算成功。【需要知道的是,后面整个学习使用过程中,我们都会用到这个库!!】
需要购买本课才能留言哦~