随笔分类 - SQL Server
摘要:问题描述: 当客户服务器不允许直接备份时,往往通过导出数据库脚本的方式来部署-还原数据库, 但是当数据库导出脚本很大,用Microsoft SQL Server Management Studio执行脚本时,往往会遇到“内存不足”的提示。 解决办法: 用微软自带的sqlcmd工具,可以导入执行。以S
阅读全文
摘要:通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码。 首先,表结构如下. 其次,在我当前D盘中有个文本文件名为2.txt的文件。 在数据库中,可以这样通过一句代码插入。 1) bulk insert: 为Sql server 中一个批量插入的操作 2)T_Demo: 要插入的表 3)'D
阅读全文
摘要:alter function test()Returns nvarchar(max)AsBeginDeclare @avg nvarchar(max)Declare @str nvarchar(max)Set @str=(Select ','+yuanshidanhao from Aj_Jibenx...
阅读全文
摘要:新增列:alter table 表名 add 新列名 数据类型删除列:alter table 表名 drop column 列名删除约束:alter table 表名 drop constraint 约束to_date('2014-08-01 00:00:00','yyyy-mm-dd hh24:...
阅读全文
摘要:create table t_sql(id int identity(1,1),code char(13),[name] nvarchar(10))gocreate function f_createcode(@bid int,@d datetime)returns char(13)as b...
阅读全文
摘要:select id from A group by id having count(1) >= 2
阅读全文
摘要:安装sql server 2008 management,提示错误:此计算机上安装了 Microsoft Visual Studio 2008 的早期版本。请在安装 SQL Server 2008 前将 VS2008 升级到 SP1。解决方法: 修改注册表。运行注册表,将HKEYLocalMachi...
阅读全文
摘要:1、执行以下sql语句即可删除所有存储过程--/**********删除所有存储过程*************************/--use 数据库名godeclare @tname varchar(8000)set @tname=''select @tname=@tname + Name ...
阅读全文
摘要:select top 每页条数 * from ( SELECT ROW_NUMBER() OVER (ORDER BY id desc) AS RowNumber,* FROM Article 条件 ) A WHERE A.RowNumber > 每页条数*(当前页数-1)示例:select to...
阅读全文
摘要:1.使用row_number()函数进行编号:如View Code 1selectemail,customerID,ROW_NUMBER()over(orderbypsd)asrowsfromQT_Customer原理:先按psd进行排序,排序完后,给每条数据进行编号。2.在订单中按价格的升序进行排...
阅读全文
摘要:1.简单的存储过程 create procedure porc_nameasselect * from 表go调用时:exec proc_name2. 带参数的存储过程create procedure proc_name@id int,@name nvarchar(50)asselect * from 表 where name=@name and id=@idgo调用时:exec proc_name 22,'李四'3.带输出参数的存储过程create proc proc_name@count int output,@name nvarchar(50)asselect @coun
阅读全文
摘要:select AuHousesID,sum(Turnover) from Auction group by AuHousesID order by sum(Turnover) desc
阅读全文
摘要:1、查询SQL中的所有表:Select TABLE_NAME FROM “你的数据库名称”.INFORMATION_SCHEMA.TABLES Where TABLE_TYPE='BASE TABLE' 执行之后,就可以看到数据库中所有属于自己建的表的名称2、查询SQL中所有表及列:Select dbo.sysobjects.name as Table_name, dbo.syscolumns.name AS Column_name FROM dbo.syscolumns INNER JOIN dbo.sysobjects ON dbo.syscolumns.id = dbo.
阅读全文
摘要:表达式DateDiff(timeinterval,date1,date2 [, firstdayofweek [, firstweekofyear]])允许数据类型: timeinterval 表示相隔时间的类型,代码为:年份 yy、yyyy 季度 qq、q月份 mm、m每年的某一日 dy、y日期 dd、d星期 wk、ww工作日 dw小时 hh分钟 mi、n秒 ss、s毫秒 ms
阅读全文
摘要:SQL报表语句 SQL获取今日、本周、本月数据本日:select * from table where datediff(dd,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段本周:select * from table where datediff(week,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段本月:select * from table where datediff(Month,C_CALLTIME,getdate())=0 --C_CALLTIME 为日期字段本季:select * from tabl..
阅读全文