sql语句基本操作
1.建表语句:create table
用法: create table 表的名字 (字段1, 字段2,。。。。)
举例:例如创建一个学生成绩表,包含的字段有,学生id,姓名,性别,班级,成绩create table score(
create table score(
sid nvarchar(10) primary key,
sname nvarchar(10) not null,
sex nvarchar(2),
sclass nvarchar(5),
score int,
check(sex in('男','女'))
);
2.插入语句:insert into
用法:insert into 表的名字 (字段1, 字段2,。。。。) values (值1,值2,。。。。)
如果字段是表中所有字段字段列表可省去,直接写表名就行了
举例:往表score中插入7条数据
insert into score values('95002','小李','男','01',82)
insert into score values('95003','小丽','女','01',83)
insert into score values('95004','小赵','男','01',67)
insert into score values('95005','小美','女','01',78)
insert into score values('95006','小田','男','01',88)
insert into score values('95007','小徐','女','01',85)
insert into score values('95008','小王','男','01',86)
3.查询语句:select
用法:select 字段 from 表名 where 条件
字段间用','分开,同样如果选择表的所有字段,可用通配符*
举例:输出score表中成绩在60到80的同学的所有信息
select * from score where score>=60 and score<=80
输出score 表中成绩为85或86或87的学生信息
select * from score where score=85 or score=86 or score=87
输出score 表中班级为95001或者性别为女性的学生的名字
select sname from score where sclass='95001' or sec='女'
4.删除语句:delete
用法:delete from 表的名字 where 条件
举例:删除score表中分数低于70分的记录
delete from score where score<70
相关文档:
摘要:本文将介绍SQL Server 2005 Analysis Services中数据挖掘算法扩展方法,在平时开发中我们需要根据要求来扩展SSAS的挖掘算法。
标签:SQL Server 2005 数据挖掘 算法
SSAS为我们提供了九种数据挖掘算法,但是在应用中我们需要根据实际问题设计适当的算法,这个时候就需要扩展SSA ......
在T-sql的写法上有很大的讲究,下面列出常见的要点:首先,DBMS处理查询计划的过程是这样的:
1、查询语句的词法、语法检查
2、将语句提交给DBMS的查询优化器
3、优化器做代数优化和存取路径的优化
4、由预编译模块生成查询规划
5、然后在合适的时间提交给系统处理执行
6、最后将执行结果返回给用户。
其次,看一下S ......
create function dbo.F_Get_No
(
@No varchar(100)
)
RETURNS bigint
AS
BEGIN
WHILE PATINDEX('%[^0-9]%',@No)>0
BEGIN
SET @No=STUFF(@No,PATINDEX('%[^0-9]%',@No),1,'') --删掉一个非数字的字符,循环结束,剩余的为数字部分
END
RETURN CONVERT(bigint,@No ......
列出TableA中有的而TableB中没有, 以及B中有而A中没有的记录:
其中两个表的结构相同,选择的Key可以多个
Select Key from
( select * from TableA
Union select * from TableB
)
group by Key
having count(Key)=1
列出TableA中有的而TableB中没有的记录:
Select Key from
( (select * from TableA
Un ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“”课程比“”课程成绩高的所有学生的学号;
SELECT a.S# from (SELECT s#,score from SC WHERE C#='001') a,
(SELECT s#,score fr ......