create table student
(
sno char(9) primary key,
sname char(20) unique,
ssex char(2),
sage smallint,
sdept char(20)
);
create table course
(
cno char(4) primary key,
cname char(40),
cpno char(4),
ccredit smallint,
foreign key(cpno) references course(cno)
);
create table sc
(
sno char(9),
cno char(4),
grade smallint,
primary key(sno,cno),
foreign key(sno) references student(sno),
foreign key(cno) references course(cno)
);
alter table student alter column sage int;
alter table course add unique(cname);
create unique index stusno on student(sno);
create unique index coucno on course(cno);
create unique index scno on sc(sno asc,cno desc);
select sno,sname from student;
select sname,sno,sdept from student;
select * from student;
select sname,2004-sage from student;
select sname NAME,'year of birth:' BIRTH,2004-sage BIRTHDAY,lower(sdept) DEPARTMENT from student;
select distinct sno NUMBER
from sc;
select sname NAME
from student
where sdept='cs';
select sname,sage
from student
where sage<20;
select distinct sno
from sc
where grade<60;
select sno
from student
where sno between 12436220 and 12436240;
select sname,ssex
from student
where sdept in('cs','ma','is');
select sname,ssex
from student
where sdept not in('cs','ma','is');
select *
from student
where sno like '200215121';
select sno
from student
where sname like '刘%';
select sno
from student
where sname like '欧阳_';
select sno
from student
where sname in('刘%','欧阳_');
select sname
from student
where sname like '_阳%';
select sno
from student
where snamd not like '刘%';
select sname
from student
where sname like 'DB\_Design'escape'\';
select sno,cno
from sc
where grade is null;
select sno,cno
from sc
where grade is not null;

  

编写SQL的更多相关文章

  1. 如果一条SQL语句太长,我们可以通过回车键来创建一个新行来编写SQL语句,SQL语句的命令结束符为分号(;)。

    1.如果一条SQL语句太长,我们可以通过回车键来创建一个新行来编写SQL语句,SQL语句的命令结束符为分号(;). 2.select查询的多个字段之间要用逗号“,”分割,如果查询涉及多个表,那多个表之 ...

  2. 编写SQL的辅助工具

    原文:编写SQL的辅助工具 今天在同事的帮助下,下载了一个工具:ApexSQL edit,可能是我孤陋寡闻,不知道还有这样的好工具,它可以在我键入SQL时,帮助我提示表的名称和列名称.还可以帮助我格式 ...

  3. [转载]编写SQL语句查询出每个各科班分数最高的同学的名字,班级名称,课程名称,分数

    [转载]编写SQL语句查询出每个各科班分数最高的同学的名字,班级名称,课程名称,分数 转载自:https://blog.csdn.net/one_money/article/details/56921 ...

  4. IDEA 配置datasource,提升编码效率,让你在 Mapper.xml 中编写sql可以飞起来~

    IDEA 2018 创建springboot工程后,如果你打开一个.sql文件,或者一个mybatis的mapper.xml文件,会提示: No data source are configured ...

  5. Atiitt 使用java语言编写sql函数或存储过程

    Atiitt 使用java语言编写sql函数或存储过程 1.1. java编写sql函数或存储过程的机制1 1.2. Java编写sp的优点1 1.3. 支持java源码,class文件,blog f ...

  6. 缓存策略 半自动化就是mybaitis只支持数据库查出的数据映射到pojo类上,而实体到数据库的映射需要自己编写sql语句实现,相较于hibernate这种完全自动化的框架我更喜欢mybatis

    springboot入门(三)-- springboot集成mybatis及mybatis generator工具使用 - FoolFox - CSDN博客 https://blog.csdn.net ...

  7. IDEA连接Mysql数据库之后,在Mapper.xml编写SQL时不会自动提示表信息问题(非常详细!)

    1.首先得连接上数据库 (一)点击IDEA右侧数据库模块 (二)选择MySql进行连接 (三)填写数据库相关配置 (四)重点!!! 这个时候点击测试连接是连接不上的,需要设置时区 (按照如下设置) ( ...

  8. Speedment -- 利用lambda编写SQL

    众所周知Java8中加入了lambda语法,这一特性也帮助Java开发者极大的简化了开发.Speedment是一个利用lambda表达式操作数据库的框架,相比Java世界中现在非常流行的mybatis ...

  9. 应用C#和SQLCLR编写SQL Server用户定义函数

    摘要: 文档阐述使用C#和SQLCLR为SQL Server编写用户定义函数,并演示用户定义函数在T-SQL中的应用.文档中实现的 Base64 编码解码函数和正则表达式函数属于标量值函数,字符串分割 ...

  10. javascript + sql编写SQL客户端工具tabris

    祝大家2018新年快乐, 前不久发现了一个创意的脚本JtSQL(java编写) 开源地址为:https://github.com/noear/JtSQL JtSQL 特点:*.结合了JS.SQL.模板 ...

随机推荐

  1. Android 连接 SQL Server (jtds方式)——下

    本文主要补充介绍jtds的查询方法,将以博主的一个实际开发程序进行说明 下图是项目的文件列表与界面效果:          运行效果: 1.三个EditText对应的是单个计划的序号.品种名.数量 2 ...

  2. Filter过滤器实现同一地址手机和电脑页面不同

    最近做一个网站,客户要求在访问主域名的时候实现电脑访问时展示电脑页面,手机访问时展示h5的手机页面,这种需求的使用还是比较多的:尤其网站需要百度推广的时候,百度推广就要求同一域名下,手机访问时展示手机 ...

  3. javaScript获取指定的cookie值

    1.获取cookie的函数 function getCookie(cookieName) { var strCookie = document.cookie; var arrCookie = strC ...

  4. 纯css+js水平时间轴

    自定义,并自动加载时间节点 当前时间节点居中,突出显示 时间动态无痕添加 效果图: 初始状态 时间左走到一定2016.1月后 html: <!-- 水平时间轴 --> <div id ...

  5. 用CSS3实现带小三角形的div框(不用图片)

    现在看到了很多带小三角形的方框,如微信.Mac版的QQ.QQ空间的时间轴等等,在聊天或者是发表的状态的内容外面都有一个带小三角形的矩形框包围着,感觉看着很不错,于是决定亲自动手写一个,我上次用的是偏移 ...

  6. 未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序(Oledb)

    解决访问Excel数据源时出现 未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序1.确保安装了Microsoft.ACE.OLEDB.12.0驱动 http://downl ...

  7. Ext.ComponentQuery.query()

    转载:http://blog.csdn.net/jiushuai/article/details/7938476 用来找特点的所有容器(Ext.container.Container)或是通过Ext. ...

  8. UISegmentControl 、UIStepper

    UISegmentControl .UIStepper UISegmentControl 1. UISegmentedControl *segmentControl = [[UISegmentedCo ...

  9. JavaScript--数组--关联(hash)数组

    关联(hash)数组的原理: hash算法: 接收一个字符串,计算出一个尽量不重复的序号 不同的字符串,计算出的序号尽量不同 相同的字符串,计算出的序号一定是相同 存入数据时: 将自定义下标名称交给h ...

  10. 8个不可不知的Mac OS X专用命令行工具(转)

    OS X的终端下通用很多Unix的工具和脚本.如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具,其实并没有任何区别. 但是OS X也提供了很多其他系统所没有的特别的命令行工具.我们推荐8个 ...