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. U盘启动安装CentOS 6.3

    无光驱U盘启动安装CentOS 6.3的一些必要条件: 1.主板要支持U盘启动 2.8G的U盘 3.UltraISO软件 http://www.linuxidc.com/Linux/2010-03/2 ...

  2. android核心服务初探

    终于进入android学习的进阶阶段,第一个课题是android的核心服务.首先,让我们来认识一下核心服务. android核心服务与app服务有所区别.app服务继承自Service基类,在app运 ...

  3. java.lang.UnsupportedClassVersionError: Bad version number in .class file

    java.lang.UnsupportedClassVersionError: Bad version number in .class file造成这种过错是ni的支撑Tomcat运行的JDK版本与 ...

  4. 关于uploadify无法起作用,界面没有效果出现

    <link href="<%: Url.Content("~/Res/uploadify/uploadify.css") %>" rel=&q ...

  5. C#错误异常列表

    Exception: 所有异常对象的基类. SystemException:运行时产生的所有错误的基类. IndexOutOfRangeException:当一个数组的下标超出范围时运行时引发. Nu ...

  6. PHPexcel数据按模板导出

    <?php header("Content-type: text/html; charset=gb2312"); error_reporting(E_ALL); ini_se ...

  7. Java对象序列化入门

      Java对象序列化入门 关于Java序列化的文章早已是汗牛充栋了,本文是对我个人过往学习,理解及应用Java序列化的一个总结.此文内容涉及Java序列化的基本原理,以及多种方法对序列化形式进行定制 ...

  8. C#部分方法定义

    C#部分方法定义 部分类也可以定义部分方法.部分方法在部分类中定义,但没有方法体,在另一个部分类中执行.在这两个部分类中,都要使用partial关键字. public partial class My ...

  9. jquery 操纵 cookies 插件(1)

    当你浏览某网站时,你硬盘上会生产一个非常小的文本文件,它可以记录你的用户ID.密码.浏览过的网页.停留的时间等信息. 当你再次来到该网站时,网站通过读取Cookies,得知你的相关信息,就可以做出相应 ...

  10. Ppthon基础学习之Dict

    一.什么是字典? 字典是Python语言中唯一的映射类型. 映射类型对象里哈希值(键,key)和指向的对象(值,value)是一对多的的关系,通常被认为是可变的哈希表. 字典对象是可变的,它是一个容器 ...