-- 期末试declare @num intdeclare @num2 int -- 局部变量的创建set @num = 99set @num2 = 100 -- 局部变量的赋值select @num * @num2 as '乘法'select @num + @num2 as '加法'use demo -- 打开数据库create table studen -- 创建表,定义表名(学号 char(12) not null primary key, -- 设定主键,逗号分隔,最后一条语句不要加逗号)go -- 批量处理use demo -- 打开数据库create table course(课程号 int not null primary key, -- 设定主键,逗号分隔,最后一条语句不要加逗号)gouse demo -- 打开数据库insert into studenvalues (),(),()-- 插入数据,逗号分隔,最后一条语句不要加逗号gouse demo -- 打开数据库insert into coursevalues (),(),() -- 逗号分隔,最后一条语句不要加逗号gouse demoselect 爱好,姓名from studenwhere 爱好 = '篮球'gouse demoselect distinct 爱好 -- distinct 去重复from studengouse demoselect 姓名from studenwhere 姓名 like '张%' --% 一个或多个字符gouse demoselect 爱好from studenwhere 爱好 like '_球' -- _ 一个字符gouse demoselect 姓名from studenwhere 姓名 not like '张%'gouse demoselect 学分,课程名,先行课from coursewhere 学分 >= '4' and 先行课 >= '5'goselect 学分,课程名,先行课from coursewhere 学分 >= '4' or 先行课 >= '5'-- 聚集函数gouse demoselect count(爱好) as '计数'from studenuse demoselect sum(班级) as '求和'from studenuse demoselect min(班级) as '最小值'from studenuse demoselect max(班级) as '最大值'from studenuse demoselect avg(班级) as '平均值'from studen-- 嵌套查询use demoselect 先行课from course cwhere 先行课 >= (select avg(s.班级) from studen s)use demoselect 先行课from coursewhere 先行课 is null -- 判断为空use demoselect 先行课from coursewhere 先行课 is not null -- 判断不是空的create database xxx, --创建数据库alter database xxx, -- 修改数据库drop database xxx, -- 删除空数据库tinyint -- 0~255tinyint -- 0~255tinyint -- 0~255bit -- 1 true 或 0 falsebit -- 1 true 或 0 falsebit --- 1 true 或 0 falsechar varchar char varchar -- 1~8000char varchar char varchar -- 1~8000date -- 日期date -- 日期date -- 日期datetime -- 日期时间datetime -- 日期时间datetime -- 日期时间create table xxx, -- 创建表create table xxx, -- 创建表create table xxx, -- 创建表use use use use use use -- 打开数据库alter table xxx,-- 修改表alter table xxx,-- 修改表alter table xxx,-- 修改表drop table xxx,-- 删除空表drop table xxx, -- 删除空表drop table xxx, -- 删除空表insert intovalues(), -- 插入数据insert intovalues(), -- 插入数据insert intovalues(), -- 插入数据declare -- 局部变量的声明declare --局部变量的创建declare -- 局部变量的创建declare --局部变量的创建set set set set set set, -- 局部变量的赋值join join join join join join join -- 内连接outer join outer join outer join outer join -- 外连接declare @num int -- 定于局部变量declare @num2 int -- 定义局部变量set @num = 99set @num2 = 100select @num * @num2 as '乘法'select @num + @num2 as '加法'create database studen -- 创建数据库(学号 char(12) not null primary key ,-- 设定主键,注意逗号分隔开,最后一条语句不要加 逗号)create database course(课程号 char(12) not null primary key -- 设定主键,逗号分隔,最后一条语句不要加逗号)gouse democreate table studen -- 创建表insert intovalues (), --插入数据(),() -- 逗号分隔,最后一条不要加逗号insert intovalues (),(),() -- 逗号分隔,select 爱好from studenwhere 爱好 like '%球' -- %一个或多个字符select 姓名from studenwhere 姓名 like '张_' -- _一个字符select 姓名from studenwhere 姓名 not like '张_' --不要的select 先行课from coursewhere 先行课 is null -- 选择为空的goselect 先行课from coursewhere 先行课 is not null -- 选择不是空的goselect distinct 爱好from studen-- distinct 消除重复goselect distinct 班级from studenselect 姓名from studenwhere 籍贯 in('北平','沙坪')-- in()括号中或select 姓名from studenwhere 所在系 = '计算机' or 爱好 = '篮球'goselect 姓名from studenwhere 所在系 = '计算机' and 爱好 = '篮球'-- 聚集函数select count(班级) as '计数'from studenselect sum(班级) as '求和'from studenselect max(班级) as '最大值'from studenselect min(班级) as '最小值'from studenselect avg(班级) as '平均值'from studenselect 先行课from course cwhere 先行课 >= (select avg(s.班级) from studen s)gocreate database xx --创建数据库alter database xx --修改数据库drop database xx -- 删除数据库tinyint -- 0~255char varchar -- 1~8000date -- 日期datedate -- 日期时间create table -- 创建表insert intovalues (), -- 插入数据declare -- 定义局部变量set -- 赋值outer join -- 内连接gouse demoselect 姓名from studenorder by 学号 asc -- order by xx asc -- 升序gouse demoselect 姓名from studenorder by 学号 desc -- order by xx desc 降序gouse demoselect 性别from studengroup by 性别having xx >= xx
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。