本文主要是介绍在SqlServer中如果存在数据库,则删除再建,如果存在表则删除再建.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
--注意:使用该sql语句生成数据库和表时,必须先在E盘下创建名为teaching的文件夹; USE master
GO
<span style="color:#FF0000;">if exists(select * from dbo.sysdatabases where name=N'teaching') drop database teaching
GO </span>
CREATE DATABASE teaching
ON
( NAME = N'teaching_data', FILENAME = N'E:\teaching\teaching.mdf', --绝对路径SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5
)
LOG ON( NAME = 'teaching_log', FILENAME = 'E:\teaching\teaching.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB
)
GO
在teaching数据库中创建学生表student
USE teaching
GO<span style="color:#FF0000;">IF EXISTS (SELECT * FROM sys.objects WHERE name = N'student'
)</span>
DROP TABLE student
CREATE TABLE student(studentno nchar(10) NOT NULL,sname nchar(8) NOT NULL,sex nchar(1) NOT NULL,birthday datetime NOT NULL,classno nchar(6) NOT NULL,point smallint NOT NULL,phone nchar(12) NOT NULL,Email nchar(20) NOT NULL,CONSTRAINT CK_sex CHECK (sex='男' OR sex='女'),CONSTRAINT PK_student PRIMARY KEY CLUSTERED (studentno ASC)
)
GO
这篇关于在SqlServer中如果存在数据库,则删除再建,如果存在表则删除再建.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!