随笔分类 -  SQL Server

摘要:mysql -h localhost -u root -p 123456 < F:/hello world/niuzi.sql 阅读全文
posted @ 2013-08-14 17:07 ajunfly 阅读(387) 评论(0) 推荐(0)
摘要:1:调整where子句中的连接顺序 a:将子查询的放到条件的最前面 b:过滤数据的条件有多到少排列2:避免使用 * 进行全表查询3:尽量将多条SQL语句压缩到一句SQL中4:用Where子句替换Having子句5:在表连接查询的时候使用表的别名6:用Exists代替In7:用表连接代替Exists8:避免在索引上使用计算9:用Union all 代替 Union 阅读全文
posted @ 2013-05-21 17:51 ajunfly 阅读(135) 评论(0) 推荐(0)
摘要:declare @path varchar(800) declare @name varchar(100) set @name = 'DatabaseName'; set @path = 'D:\DataBaseBack\' + @name + '_' + convert(varchar(50),getdate(),112)+'.bak' backup database @name to disk = @path with noinit,nounload,noskip,stats=10,noformat 阅读全文
posted @ 2013-05-17 14:08 ajunfly 阅读(124) 评论(0) 推荐(0)
摘要:static string str = "|add|and|exec|insert|select|delete|update|chr|mid|master|or|truncate|char|declare|join|"; public static bool DataVerify() { string type = HttpContext.Current.Request.RequestType.ToLower(); bool flag = true; if (type == "post") { for (int i = 0; i < HttpCon 阅读全文
posted @ 2013-02-16 17:58 ajunfly 阅读(336) 评论(0) 推荐(0)
摘要:1:首先是 select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1 生成带序号的集合2:再查询该集合的 第 1 到第 5条数据 select * from (select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1) as temp where rowNumber between 1 and 5完整的Sql语句declare @pagesize int; declare @pageindex 阅读全文
posted @ 2012-12-12 15:51 ajunfly 阅读(21288) 评论(0) 推荐(3)
摘要:exec sp_configure 'show advanced options',1reconfigureexec sp_configure 'Ad Hoc Distributed Queries',1reconfigure 阅读全文
posted @ 2012-06-06 15:15 ajunfly 阅读(899) 评论(0) 推荐(0)
摘要:--新增和删除触发器alter trigger tri_TC on t_c for INSERT,deleteasbegin set XACT_ABORT ON declare @INSERTCOUNT int; declare @DELETECOUNT int; declare @UPDATECOUNT int; set @INSERTCOUNT = (select COUNT(*) from inserted); set @DELETECOUNT = (select COUNT(*) from deleted); set @UPDATECOUNT = () if(@INSERTCOUNT 阅读全文
posted @ 2012-05-30 16:50 ajunfly 阅读(1465) 评论(0) 推荐(0)
摘要:Begin Transaction TranDocumentControl_Insert 开始事务Insert Into table valuies () //执行动作If @@Error<>0 Goto EndProc //如果执行结果@@Error错误记录不等于0,则表示动作执行出错,那么接着执行 endproc程序段else Commit Transaction TranDocumentControl_Insert //如果执行结果等于0,表示动作执行成功,则提交事务Return 0 EndProc:RollBack Transaction TranDocumentContr 阅读全文
posted @ 2012-05-22 10:09 ajunfly 阅读(144) 评论(0) 推荐(0)
摘要:--创建存储过程CREATE PROCEDURE procedure_test @ID VARCHAR(100)AS DECLARE @ReturnValue varchar(100)BEGINSET NOCOUNT ON; set @ReturnValue = @ID return @ReturnValueENDGO--------执行下面sql语句,获得上面存储过程的返回值declare @value varchar(100);exec @value = procedure_test '1111111';select @value 阅读全文
posted @ 2012-05-18 11:14 ajunfly 阅读(323) 评论(0) 推荐(0)
摘要:USE [ZJPJTX]GO/****** Object: UserDefinedFunction [dbo].[fun_GradeDiff] Script Date: 05/18/2012 10:57:42 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER FUNCTION [dbo].[fun_GradeDiff] (@sum decimal(10,4)) RETURNS char(1) AS BEGIN declare @returnValue char(1)declare @temp table (startMoney 阅读全文
posted @ 2012-05-18 10:59 ajunfly 阅读(4451) 评论(0) 推荐(0)
摘要:表t_c 和t_p如上图select * from t_cselect * from t_p查询方法一: select * from (select row_number() over(partition by cid order by cdate desc) as rowid,* from t_p) T where T.rowid<=5 使用sql2005的特性 row_number() over()方法二: declare @temp table(id int,cid int,cdate datetime); declare @id int; declare cur cursor.. 阅读全文
posted @ 2011-09-22 11:05 ajunfly 阅读(147) 评论(0) 推荐(0)
摘要:select row_number() over(order by yw desc),* from score --有并列时也不重名 1.2.3.4....select rank() over(order by yw desc),* from score--有别列是调名 1.2.2.2.3.4.......... 阅读全文
posted @ 2011-09-21 17:51 ajunfly 阅读(392) 评论(0) 推荐(0)
摘要:alter procedure Page@TableName varchar(255),--表名 @ID varchar(50), --主表的主键@StrGetFields varchar(1000) = '*', --需要返回的列@PageSize varchar(10),--页尺寸@PageIndex varchar(10),--页码 @StrWhere varchar(1500), --查询条件 @PxName varchar(255), --排序的字段@OrderType varchar(1)='a', --设置排序类型,0:asc,1:desc @Co 阅读全文
posted @ 2011-09-20 17:53 ajunfly 阅读(187) 评论(0) 推荐(0)