![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
常用语法SQL
$张张
在校大学生,正在学习Java,分享学习中收获到的内容,每一篇文章都包含自己的思想,欢迎指正!
展开
-
数据库多表查询
--多表查询--查询选修了课程名为“信息系统”的学生学号和姓名select sno,snamefrom studentwhere sno in(select snofrom course,scwhere cname='信息系统' and course.cno = sc.cno);--或者select sno,snamefrom studentwhere sno in( select sno from sc where cno in( select cno from原创 2021-04-12 17:13:02 · 1257 阅读 · 0 评论 -
数据库单表查询
--创建student表格create table student( sno int primary key, sname char(10) unique, ssex char(5), sage int, sdept char(10));--创建course表create table course( cno int primary key, cname char(10) unique, cpno int, ccredit int, foreign key(cpno) ref原创 2021-04-12 17:11:57 · 1235 阅读 · 0 评论 -
数据库常用语法
--目标表达式还可以是函数select COUNT(Sname)from student;--指定distinct关键词可以消除重复的行,否则将输出所有的行--查询选修了课程的学生学号select distinct snofrom sc; --查询选修了计算机科学系全体学生的名单 select sname from student where sdept='CS'; --查询所有年龄在20岁以下的学生姓名及其年龄 select sname,sage from student原创 2021-04-10 16:11:00 · 1213 阅读 · 0 评论 -
SQL server单表查询
-- 单表查询--查询全体学生的学号和姓名select sno,sname --必选语句,指定要显示的属性列from student --必选语句,指定从那个表或者视图内查询where sage=18; --查询条件--选出所有属性列:*select * --用*表示所有的列from student;--select后面可以跟表达式select sno,2021-sage --两列,列名分别为sno,和2021-sagefrom stude原创 2021-04-05 18:00:12 · 1534 阅读 · 0 评论 -
SQL server中创建、删除、添加表、索引等
```sql--创建student表格create table student( sno int primary key, sname char(10) unique, ssex char(5), sage int, sdept char(10));--创建course表create table course( cno int primary key, cname char(10) unique, cpno int, ccredit int, foreign key(c.原创 2021-04-05 17:07:02 · 1348 阅读 · 0 评论