简单的SQL语句
答案:1 悬赏:50 手机版
解决时间 2021-05-17 17:11
- 提问者网友:不爱我么
- 2021-05-17 04:10
简单的SQL语句
最佳答案
- 五星知识达人网友:孤老序
- 2021-05-17 04:18
use master
go
exec sp_configure 'show advanced options', 1
go
reconfigure
go
exec sp_configure 'xp_cmdshell', 1
go
reconfigure
go
exec xp_cmdshell 'md F:\数据库\'
goif exists (select dbid from sysdatabases where [name] = 'school')
drop database school
go
---创建数据库school
create database school
on primary
(
name = 'school',
filename = 'F:\数据库\school.mdf'
)
log on
(
name = 'school_log',
filename = 'F:\数据库\school_log.ldf'
)
gouse school
go
---创建表student
create table student
(
[student_id] int identity(1,1) primary key not null,
[name] varchar(50) not null,
[class_id] int not null,
)
go
---创建表class
create table class
(
[class_id] int identity(1,1) primary key not null,
[name] varchar(50) not null,
)
go ---添加主外键关系
alter table student add constraint FK_class_id foreign key(class_id) references Class(class_id)
go ---插入班级表数据
insert into class([name]) values('一班')
insert into class([name]) values('二班') ---插入学生表数据
insert into student([name], [class_id]) values('学生1', 1)
insert into student([name], [class_id]) values('学生2', 1)
insert into student([name], [class_id]) values('学生3', 1)
insert into student([name], [class_id]) values('学生4', 2)
insert into student([name], [class_id]) values('学生5', 2)
insert into student([name], [class_id]) values('学生6', 2) ---查询一班所有学生成绩按降序排列
select * from student where [class_id] = 1 order by [s......余下全文>>
go
exec sp_configure 'show advanced options', 1
go
reconfigure
go
exec sp_configure 'xp_cmdshell', 1
go
reconfigure
go
exec xp_cmdshell 'md F:\数据库\'
goif exists (select dbid from sysdatabases where [name] = 'school')
drop database school
go
---创建数据库school
create database school
on primary
(
name = 'school',
filename = 'F:\数据库\school.mdf'
)
log on
(
name = 'school_log',
filename = 'F:\数据库\school_log.ldf'
)
gouse school
go
---创建表student
create table student
(
[student_id] int identity(1,1) primary key not null,
[name] varchar(50) not null,
[class_id] int not null,
)
go
---创建表class
create table class
(
[class_id] int identity(1,1) primary key not null,
[name] varchar(50) not null,
)
go ---添加主外键关系
alter table student add constraint FK_class_id foreign key(class_id) references Class(class_id)
go ---插入班级表数据
insert into class([name]) values('一班')
insert into class([name]) values('二班') ---插入学生表数据
insert into student([name], [class_id]) values('学生1', 1)
insert into student([name], [class_id]) values('学生2', 1)
insert into student([name], [class_id]) values('学生3', 1)
insert into student([name], [class_id]) values('学生4', 2)
insert into student([name], [class_id]) values('学生5', 2)
insert into student([name], [class_id]) values('学生6', 2) ---查询一班所有学生成绩按降序排列
select * from student where [class_id] = 1 order by [s......余下全文>>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯