随笔分类 -  SQLServer

SQLServer创建触发器
摘要:建数据库create database school--建表 use school create table students (s_id int identity(1,1) primary key,--设主键,为自增id s_name varchar(20) not null, s_classId int )create table class ( c_id int identity(1,1) primary key,--设主键,为自增id c_className varchar(20) not null )create table student_Score ( ss_id int ide 阅读全文

posted @ 2014-03-13 11:33 riky1989 阅读(521) 评论(0) 推荐(0)

SQLServer内链接,外连接
摘要: 阅读全文

posted @ 2014-02-28 10:56 riky1989 阅读(139) 评论(0) 推荐(0)

ROW_NUMBER() OVER函数的基本用法用法
摘要:语法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)简单的说row_number()从1开始,为每一条分组记录返回一个数字,这里的ROW_NUMBER() OVER (ORDER BY xlh DESC) 是先把xlh列降序,再为降序以后的没条xlh记录返回一个序号。示例:xlh row_num1700 11500 21085 3710 4row_number() OVER (PARTITION BY COL1 ORDER BY COL2)表示根据COL1分组,在分组内部根据 COL2排序,而此函数计算的值就表示每组内部排序后的顺序 阅读全文

posted @ 2014-02-24 10:09 riky1989 阅读(140) 评论(0) 推荐(0)

查询重复数据
摘要:1、使用GROUP BY...HAVING查询重复数据--找出字段1重复的行SELECT * FROM 表名 WHERE 字段1 IN (SELECT 字段1 FROM 表名 GROUP BY 字段1 HAVING COUNT(*) > 1)--找出字段1,字段2均重复的行SELECT a.* FROM 表名 AS a LEFT OUTER JOIN (SELECT 字段1,字段2 FROM 表名 GROUP BY 字段1,字段2HAVING (COUNT(*) > 1)) AS b ON a.字段1= b.字段1WHERE (a.字段2 = b.字段2)2、根据字段id(唯... 阅读全文

posted @ 2014-02-20 17:37 riky1989 阅读(269) 评论(0) 推荐(0)

SQL Server2008中删除重复记录
摘要:在Database中可能由于某种原因如用户输入,导入数据失败等 导致了重复记录. 如果你没有用主键,约束,或来其它机制实现数据完整性,那最后总是重复记录在你的数据库中.现在让我们来看在SQL SERVER 2008中如何删除这些记录, 首先,可以模拟造一些简单重复记录:Create Table dbo.Employee ([Id] int Primary KEY , [Name] varchar(50), [Age] int, [Sex] bit default 1)Insert Into Employee ([Id] , [Name] , [Age] , [Sex] ) Values(1,& 阅读全文

posted @ 2014-02-20 17:16 riky1989 阅读(237) 评论(0) 推荐(0)

SQLServer数据集合的交、并、差三种集合运
摘要:SQLServer2005通过intersect,union,except和三个关键字对应交、并、差三种集合运算他们的关系对应如下createtablet1 (aint)insertintot1select1unionselect2unionselect3createtablet2 (aint)insertintot2select3unionselect4unionselect5goselect*fromt1unionselect*fromt2go/* 求表并集12345*/select*fromt1unionallselect*fromt2go/*求表并集不过滤重复123345*/selec 阅读全文

posted @ 2014-01-10 09:13 riky1989 阅读(174) 评论(0) 推荐(0)

导航