Sql 备忘——行号
摘要:SELECT row_number() over(order by Product.ID) as [row_number]
阅读全文
posted @
2014-07-25 17:41
朝着
阅读(127)
推荐(0)
Sql 语句收集——行转列
摘要:SQL行转列汇总 PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P完整语法:table_sourcePIVOT(聚合函数(value_column)F...
阅读全文
posted @
2014-06-13 14:39
朝着
阅读(512)
推荐(0)
处理百万级以上的数据提高查询速度的方法
摘要:《 数据库技术内幕 》处理百万级以上的数据提高查询速度的方法: 1.应尽量避免在 where 子句中使用!=或操作符,否则将引擎放弃使用索引而进行全表扫描。 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 orderby 涉及的列上建立索引。 3.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num isnull 可以在num上设置默认值0,确保表中num列没有null值,然后这样查询: select id from t where num=0 4.应尽量避...
阅读全文
posted @
2014-03-26 15:33
朝着
阅读(316)
推荐(0)
动态添加列
摘要:if exists (select * from sysobjects where name='aa')drop proc aagocreate proc aaas create table #tb2 ( id int, uName varchar(10) );...
阅读全文
posted @
2014-01-10 00:25
朝着
阅读(165)
推荐(0)
无限级菜单操作(存储过程、游标、递归、事务)
摘要:if exists (select 1 from sysobjects where id = object_id('tb_Menu') and type = 'U') drop table tb_Menugo/*==============================================================*//* Table: tb_Menu *//*========================...
阅读全文
posted @
2013-11-30 01:10
朝着
阅读(602)
推荐(0)
无限极操作
摘要:if exists (select 1 from sysobjects where id = object_id('tb_Menu') and type = 'U') drop table tb_Menugo/*==============================================================*//* Table: tb_Menu *//*========================...
阅读全文
posted @
2013-11-29 12:00
朝着
阅读(225)
推荐(0)
无限级菜单
摘要:if exists(select * from sysobjects where name='tb_tree')drop table tb_treegocreate table tb_tree( id int primary key identity, name varchar(50), pId int, level int, sort int, cNum int)goinsert into tb_tree(name,pId,level,sort,cNum) values('节点1',0,1,0,6);insert into tb_tree(name,pId..
阅读全文
posted @
2013-11-28 17:54
朝着
阅读(279)
推荐(0)
多级菜单删除
摘要:if exists (select * from sysobjects where name='proc_menu_delete')drop proc proc_menu_deletegocreate proc proc_menu_delete(@id int)as declare @count int,@tmpid intselect @count=count(1) from Menu where Id=@idif(@count>0)begin declare ar_cursor cursor local for select id from menu where pi
阅读全文
posted @
2013-11-26 22:51
朝着
阅读(318)
推荐(0)
SQL面试题
摘要:下列语句部分是Mssql语句,不可以在access中使用。 SQL分类:DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK) 首先,简要介绍基础语句:1、说明:创建数据库CREATE DATABASE database-name 2、说明:删除数据库drop database dbname 3、说明:备份sql server--- 创建 备份数据的 deviceUSE masterEXEC sp_addumpdevi
阅读全文
posted @
2013-07-15 12:41
朝着
阅读(398)
推荐(0)
通用分页存储过程
摘要:alter proc proc_GetRecordFromPage @tblName varchar(255), -- 表名 @fldName varchar(255), -- 字段名 @PageSize int = 1, -- 页尺寸 @PageIndex int = 1, -- 页码 @IsCount bit = 0, -- 返回记录总数, 非0 值则返回 @OrderType bit = 1, -- 设置排序类型, 非0 值则...
阅读全文
posted @
2013-07-08 22:59
朝着
阅读(119)
推荐(0)
存储过程获得最新订单号
摘要:create proc proc_No@id varchar(14) output,@date varchar(20),@tname varchar(50),@col varchar(50),@type char(2)asdeclare @aa nvarchar(14)declare @sql nvarchar(255) set @sql=('select @aa=max('+@col+') from '+@tname+' where SUBSTRING('+@col+',3,8)=convert(varchar(8),CONVERT(d
阅读全文
posted @
2013-07-08 22:58
朝着
阅读(219)
推荐(0)
Sql Service 存储过程、触发器
摘要:if exists (select * from sysobjects where name='tb_admin')drop table tb_admingocreate table tb_admin( id int identity(1,1) primary key, aname varchar(50) not null)go--存储过程if exists (select * from sysobjects where name='proc_adminInsert')drop procedure proc_adminInsertgocreate procedu
阅读全文
posted @
2013-07-05 18:00
朝着
阅读(193)
推荐(0)
SQL 批量添加的语法
摘要:1.--添加一条记录 2. insert into tableName(col1,col2,col3) values (val1,val2,val3) 3.--添加多条记录 4. insert into tableName(col1,col2,col3) 5. select val1,val2,val3 6. union all 7. select val1,val2,val3 8. 、、、 9.---当把 union all 换成 all 后,相同记录只插入一次,不会重复插入(必须所有字段都相同时,自动增长列除外) 10. 11.---从另外的一张...
阅读全文
posted @
2013-07-02 16:04
朝着
阅读(864)
推荐(0)
SqlService 数据操作
摘要:存储过程: if exists(select * from sysobjects where name='proce_name') drop procedure proce_name go create procedure proce_name @id int, @name varchar(10), @outname varchar(20) out as set @outname='历史';godeclare @aa varchar(10); exec proce_name 1,'',@aa out; print @aa;
阅读全文
posted @
2013-07-02 15:56
朝着
阅读(202)
推荐(0)