欢迎使用CSDN-markdown编辑器

来源:互联网 发布:mac怎么打拼音 编辑:程序博客网 时间:2024/06/06 03:58
create DATABASE students create TABLE t_soures(    c_number char(10) not null PRIMARY key,    c_name char(30) not null,    hours int ,    credit real   ) create TABLE t_score(  s_number char(10) foreign key references )USE [students];GODROP TABLE [dbo].[t_soures];GOselect s_number, t_socre.c_number, socer  FROM t_socre, t_sourse where (dbo.t_socre.c_number = dbo.t_sourse.c_number)select * FROM t_socre where socer <90select * from t_student where polity='团员' AND sex='男'BETWEEN 是在一个范围 (range) 内抓出数据库中的值。BETWEEN 这个子句的语法如下:  这将选出栏位值包含在值一及值二之间的每一笔资料。在 SQL 中,在这个用法下,事先已经知道至少一个需要的值,而将这些知道的值都放入 IN这个子句。 IN 指令的 语法为下:  在括弧内可以有一或多个值,而不同值之间由逗点分开。值可以是数目或是文字。若在括弧内只有一个值,那这个子句就等于select * from t_student where polity in('团员','非')select * from t_student where birthday BETWEEN '1996/12/1' AND '1997/2/2'USE [students];GODROP TABLE [dbo].[t_soures];GO
/* 联合查询 *//* 内联   高效,低效  把用户信息、积分、等级都列出来*/select * FROM t_student, t_socre where dbo.t_student.s_number = dbo.t_socre.s_numberselect * from t_student inner join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number/* 左连   显示左表T1中的所有行,并把右表T2中符合条件加到左表T1中;右表T2中不符合条件,就不用加入结果表中,并且NULL表示。*/select * from t_student left outer join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number/* 右表无004信息 所以用null代替 *//* 右连     显示右表T2中的所有行,并把左表T1中符合条件加到右表T2中;左表T1中不符合条件,就不用加入结果表中,并且NULL表示。*/select * from t_student  right outer join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number/* 全连     显示左表T1、右表T2两边中的所有行,即把左联结果表+右联结果表组合在一起,然后过滤掉重复的 */select * from t_student   full outer join dbo.t_socre ON dbo.t_socre.s_number = dbo.t_student.s_number
/*  update 员工表 set 部门编号=01 --如果01是字符型,则加上单引号where 员工编号='0004'update t_socre set s_number='003' where c_number ='01'*/select * from t_student where s_number = any (   select s_number FROM t_socre    Group by s_number    having COUNT(c_number)>=2)
create table t_student(    s_number char(10) primary key,    s_name char(30) ,    sex char(2) default '男',    birthday datetime,    polity char(4))
0 0
原创粉丝点击