SQLServer创建表

use master
go

--判断当前数据库是否存在
if exists(select*from sysdatabases where name = 'StudentManageDB')
drop database StudentManageDB
go

--创建数据库

create database StudentManageDB
on primary
(
	name = 'StudentManageDB_data',--数据库逻辑文件名
	filename = 'D:\DB\StudentManageDB_data.mdf',--数据库物理文件名
	size = 10 MB,--数据库文件初试大小
	filegrowth = 50% --数据文件增长量
),

(
	name = 'StudentManageDB_data1',
	filename = 'D:\DB\StudentManageDB_data1.ndf',
	size = 10 MB,--数据库文件初试大小
	filegrowth = 50% --数据文件增长量
)


--创建日志文件
log on
(
	name = 'StudentManageDB_log',--数据库逻辑文件名
	filename = 'D:\DB\StudentManageDB_log.Idf',--数据库物理文件名
	size = 10 MB,--数据库文件初试大小
	filegrowth = 2MB --数据文件增长量
),

(
	name = 'StudentManageDB_log1',--数据库逻辑文件名
	filename = 'D:\DB\StudentManageDB_log1.Idf',--数据库物理文件名
	size = 10 MB,--数据库文件初试大小
	filegrowth = 2MB --数据文件增长量
)
go


use StudentManageDB 
go --指向数据库

if exists (select*from sysobjects where name='Students')
drop table Students
go

create table Students
(
	StudentId int identity(10000,1),--学号,从10000开始,每次递增1
	StudentName varchar(20) not null,--姓名
	Gender char(20) not null, --性别
	Birthday datetime not null, --出生日期
	StudentIdNo numeric(18,0) not null, --18位
	Age int	not null, --年龄
	PhoneNumber varchar(50), --50个字符
	StudentAdress varchar(500),
	ClassId int not null --班级外键
)
go

--select * from Students

--创建班级表

if exists(select * from sysobjects where name = 'StudentClass')
drop table StudentClass
go

create table StudentClass
(
	ClassId int primary key, --建立主键
	ClassName varchar(20) not null
)
go

--创建成绩表

if exists (select * from sysobjects where name ='ScoreList')
drop table ScoreList
go

create table ScoreList
(
	Id int identity(1,1) primary key, --建立主键 identity自增 
	StudentId int not null,  --学号外键
	Csharp int null,
	SQLServer int null,
	UpdateTime datetime not null
)

go

--创建管理员表

if exists (select * from sysobjects where name = 'Admins')
drop table Admins
go

create table Admins
(
	LoginId int identity(1000,1) primary key,
	LoginPwd varchar(20) not null,
	AdminName varchar(20) not null
)

go

--select * from Students

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘诺西亚的火山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值