-- 3-5  创建表Studnet
create table Student
(Sno char(9) primary key,
Sname char(20) UNIQUE,
Ssex CHAR(2),
Sage smallint,
Sdept char(20)
);

-- 3-6 创建表Course
create table course
(Cno char(4) primary key ,
Cname char(40) not null,
Cpno char(4),
Ccredit smallint,
foreign key (cpno) references course(cno)
);

-- 3-7 创建表SC
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)
);
-- 3-8向Studnet表中添加入学时间列
alter table Student Add S_entrance Date;

-- 3-9 修改age 的数据类型
alter table Student alter column Sage int;

-- 3-10  使得Cname为唯一
alter table Course add unique(Cname);

-- 3-12 查询Student表中的所有数据
select * from Student;

-- 向Student表中添加数据
insert into Student values('12','kjdfh','1',12,'yd','2016-12-10');

-- 3-12 删除相应表信息
drop table Student CASCADE;

-- 3-13
 --按学号升序建立唯一索引
 create unique index Stusno ON Student(Sno);
 --按课程号升序建立唯一
 create unique index Coucno ON Course(Cno);
 -- 按学号升序、课程号降序家建立唯一索引
 create unique index sCno ON SC(Sno ASC,Cno DESC);

-- 3-14 将SC表的SCno 索引名修改为SCSno
alter index SCno RENAME TO SCSno;

-- 3-15 删除Student 表的Stusname索引
drop index Stusname;

-- 3-16 查询全体学生的学号与姓名
select Sno,Sname from Student;

-- 3-17 查询全体学生的姓名、学号、所在系
select Sname,Sno,Sdept
from Student;

-- 3-18 查询全体学生的详细记录
Select * from Student;

-- 3-19 查询全体学生的姓名、及其出生年份
select Sname,2014-Sage from Student;

-- 3-20 查询全体学生的姓名、出生年份和所在的院系,要求用小写字母表示系名
select Sname,'Year of irth:',2014-Sage,LOWER(Sdept) from Student;

-- 3-21  查询选修了课程的学生学号
select Sno from SC;

-- 3-22 查询计算机科学系的全体学生的名单
select Sname from Student  where Sdept='CS';

-- 3-23 查询所有考试年龄在20 岁以下的学生姓名及年龄
select Sname,Sage from Student where Sage<20;

-- 3-24 查询考试成绩不及格的学生学号

sql server数据库语句的更多相关文章

  1. SQL SERVER 数据库备份的三种策略及语句

    1.全量数据备份    备份整个数据库,恢复时恢复所有.优点是简单,缺点是数据量太大,非常耗时 全数据库备份因为容易实施,被许多系统优先采用.在一天或一周中预定的时间进行全数据库备份使你不用动什么脑筋 ...

  2. SQL Server数据库性能优化之SQL语句篇【转】

    SQL Server数据库性能优化之SQL语句篇http://www.blogjava.net/allen-zhe/archive/2010/07/23/326927.html 近期项目需要, 做了一 ...

  3. SQL SERVER数据库状态(脱机,联机,可疑)及SQL设置语句详解

      首先我们应该知道数据库总是处于一个特定的状态中,下面先来了解一下数据库的常见的三种状态:1,脱机:我们可以在Microsoft SQL Server Management中看到该数据库,但该数据库 ...

  4. Oracle,SQL Server 数据库较MySql数据库,Sql语句差异

    原文:Oracle,SQL Server 数据库较MySql数据库,Sql语句差异 Oracle,SQL Server 数据库较MySql数据库,Sql语句差异 1.关系型数据库 百度百科 关系数据库 ...

  5. 【转】sql server数据库操作大全——常用语句/技巧集锦/经典语句

    本文为累计整理,有点乱,凑合着看吧! ☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆ ☆ ☆ ☆ sql 宝 典 ☆ ☆ ☆ 2012年-8月 修订版 ☆ ...

  6. SQL语句操作SQL SERVER数据库登录名、用户及权限

    要想成功访问 SQL Server 数据库中的数据, 我们需要两个方面的授权: 获得准许连接 SQL Server 服务器的权利: 获得访问特定数据库中数据的权利(select, update, de ...

  7. jsp页面使用<% 语句%> SQL Server数据库报空指针异常(在控制台可以正常执行)

    一直反感用SQL Server数据库,很影响电脑性能!!数据库作业不得不用 前几天作业一直报空指针异常: 自己检查了所传参数,和数组不为空 数据库查询语句不为空 然后查看SQL服务是否启动  主要是S ...

  8. SQL Server 数据库部分常用语句小结(三)

    21.SQL运行Log的读取 .EXEC xp_readerrorlog 0,1,null,null,'开始时间','结束时间' 22. Alwayson 状况及传输情况监控 SELECT ar.re ...

  9. SQL Server数据库定时自动备份

    SQL Server 数据库定时自动备份[转]   在SQL Server中出于数据安全的考虑,所以需要定期的备份数据库.而备份数据库一般又是在凌晨时间基本没有数据库操作的时候进行,所以我们不可能要求 ...

随机推荐

  1. Oracle中有个tkprof来格式化oracle的trace文件

    1.MySQL日志文件系统的组成2.慢查询日志3.慢查询日志演示long_query_time : 设定慢查询的阀值,超出次设定值的SQL即被记录到慢查询日志,缺省值为10sslow_query_lo ...

  2. Android课程---用进度条改变图片透明度

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  3. IOS网络第一天 - 02SDWebImage

    **************SDWebImage加载图片 #import "HMAppsViewController.h" #import "HMApp.h" ...

  4. generator自动生成mybatis配置和类信息

    generator自动生成mybatis的xml配置.model.map等信息: 1.下载mybatis-generator-core-1.3.2.jar包.        网址:http://cod ...

  5. 如何使用 vimdiff 来 git diff /svn diff

    #git 如何实现vimdiffgit config --global diff.tool vimdiff git config --global difftool.prompt false git ...

  6. an alternative to symmetric multiprocessing

    COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION 17.5 CLUSTERSAn impor ...

  7. only for equality comparisons Hash Index Characteristics

    http://dev.mysql.com/doc/refman/5.7/en/index-btree-hash.html Hash Index Characteristics Hash indexes ...

  8. [troubleshoot][daily][archlinux][pacman] pacman 与 pip 包文件冲突

    今天滚系统,再次遭遇包冲突: (/) checking % error: failed to commit transaction (conflicting files) python2-reques ...

  9. HTML5 Canvas绘文本动画(使用CSS自定义字体)

    一.HTML代码: <!DOCTYPE html> <html> <head> <title>Matrix Text - HTML5 Canvas De ...

  10. JS模块化库seajs体验

    seajs http://seajs.org/docs/en.html#intro https://github.com/seajs/seajs/releases Extremely simple e ...