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. JDK5-静态导入

    import static 1. 导入一个类内所有静态成员 import static java.lang.Math.*; public class StaticImport { public sta ...

  2. html02表格的使用

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. Log4net 配置注意事项

    1. 首先引入Log4net程序集 2.修改webconfig配置文件 在 configuration 节点下面添加如下节点 <configSections> <section na ...

  4. Java枚举类型理解

    Enum格式理解 Enum的格式可以看做跟class关键字一样 class的定义格式如下: public class abc{ } enum的定义格式如下: Public enum abc { } 引 ...

  5. iPhone真机测试Crash信息分析

    一.获取Crash Log的方式 在iOS开发过程,当应用已经打包,iPhone设备通过ipa的包安装应用后,在使用过程发现crash,那么如何获取crash日志呢,现提供如下四种获取crash日志的 ...

  6. Swift - 33 - 返回函数类型和函数嵌套

    //: Playground - noun: a place where people can play import UIKit /*---------------------------返回函数类 ...

  7. react服务端渲染(同构)

    学习react也有一段时间了,使用react后首页渲染的速度与seo一直不理想.打算研究一下react神奇服务端渲染. react服务端渲染只能使用nodejs做服务端语言实现前后端同构,在后台对re ...

  8. int, NSInteger, NSUInteger, NSNumber的区别

    新手在接触iOS或者Mac开发的时候,看到int和NSInteger,一般不清楚应该用哪个比较合适.我们先来查看下NSInteger的定义 #if __LP64__ || (TARGET_OS_EMB ...

  9. JVM内存管理及垃圾回收

    一.JVM内存的构 Java虚拟机会将内存分为几个不同的管理区,这些区域各自有各自的用途,根据不同的特点,承担不同的任务以及在垃圾回收时运用不同的算法.总体分为下面几个部分: 程序计数器(Progra ...

  10. C#制作ActiveX控件及部署升级(摘自网络)

    使用C#开发ActiveX控件 控件开发.制作CAB包.签名.部署 ActiveX控件以前也叫做OLE控件,它是微软IE支持的一种软件组件或对象,可以将其插入到Web页面中,实现在浏览器端执行动态程序 ...