1. Backup the CYZDATA database as the target library 1.bak file and store it in the disk.
use CYZDATA;
backup database CYZDATA to disk='D:\\Desktop\\backup\\目标库1.bak' with format,name='full backup of CYZDATA'
2. Determine whether the table exists in sqlserver, and delete it first if it exists. (The script written in sqlserver is Drop)
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[测试表]') AND type in (N'U'))
DROP TABLE [dbo].[测试表]
GO
3. Determine whether the database name exists.
use master --切换到master数据库
go
if exists(select 1 from sysdatabases where name = 'tour')
begin
drop database tour
end
go
4. Create the database
create database tour
on ( name = 'tour_mdf', --数据文件逻辑名
filename = 'D:\tour.mdf',--数据文件存放路径
size = 10MB,--初始大小
maxsize = 10MB,--最大大小
filegrowth = 1MB--增长速度 )
5. Create a table stuMarks for the database tour, first determine whether it exists, delete it if it exists, and create it if it does not exist
use tour
if exists(select * from sysobjects where name='stuMarks') drop table stuMarks
create table stuMarks
(ExamNo varchar(6) not null , --考号
stuNo varchar(6) not null, --学号
writtenExam int not null, --笔试成绩
LabExam int not null --机试成绩 )
go