使用程序:SQL Server 2008
时间:2020年6月
练习题目:创建多张表的数据库
要求:掌握并理解单张表创建和多张表创建的区别
--使用主数据库
use master
go
--判断当前数据库是否存在,存在则删除
if exists (select * from sys.databases where name = '数据库名')
drop database DigitalProductShop
go
--创建数据库
create database 数据库名
go
--使用创建的数据库
use 数据库名
go
--判断当前数据库中是否存在创建的表,存在则删除
if exists (select * from sys.objects where name = '表名1')
drop table 表名1
if exists (select * from sys.objects where name = '表名2')
drop table 表名2
go
--创建表
create table 表名1
(
表的内容
)
create table 表名2
(
表的内容
)
go
要点:
1、多表创建与单表创建区别不大。(不涉及约束的情况下,这个以后再说)
本文详细介绍如何使用SQLServer2008创建包含多张表的数据库,包括判断数据库及表是否存在并进行删除,以及创建数据库和表的具体步骤。
459

被折叠的 条评论
为什么被折叠?



