当前位置:Gxlcms > 数据库问题 > 创建(或者删除)数据库、表

创建(或者删除)数据库、表

时间:2021-07-01 10:21:17 帮助过:6人阅读

USE master --使用系统数据库 2 GO 3 IF EXISTS(SELECT * FROM sysdatabases WHERE name=NDB_MyStudentLife) 4 DROP DATABASE [DB_MyStudentLife]; --如果要创建的数据库存在的话,就删除 5 GO 6 CREATE DATABASE [DB_MyStudentLife] --创建数据库 7 GO 8 USE [DB_MyStudentLife] --使用数据库 9 GO 10 IF EXISTS(SELECT * FROM sysobjects WHERE name=NMyClass) 11 DROP TABLE [MyClass] --如果要创建的数据表存在的话,就删除(注意sysobjects,一定要全部是小写的,不然有错误,不能写成大写的。) 12 GO 13 CREATE TABLE MyClass --创建数据表 14 ( 15 C_ID INT NOT NULL PRIMARY KEY IDENTITY(1,1), --班级编号 16 C_Name NVARCHAR(200) not null, --班级名称 17 C_Descr nvarchar(max) not null --班级简介 18 19 ); 20 GO 21 IF EXISTS(SELECT * FROM sysobjects WHERE name=NMyStudent) 22 DROP TABLE MyStudent 23 GO 24 CREATE TABLE MyStudent 25 ( 26 S_ID int not null primary key identity(1,1), --学号 27 S_Name nvarchar(50) not null, --姓名 28 S_Gender char(2) not null, --性别 29 S_Address nvarchar(max) not null , --地址 30 S_Phone nvarchar(50)not null, --电话 31 S_Age int not null, --年龄 32 S_Birthday datetime not null, --生日 33 S_CardID int not null, --身份证号码 34 S_CID int not null references MyClass(C_ID) --班级编号 35 36 );

 

创建(或者删除)数据库、表

标签:

人气教程排行