SQL学习笔记
计算字符的长度
select len(' abc')--4
select len('abc ')--3
select len('你好')--2
len函数返回的是字符数,不是字节数。
利用CMD写文件,数据太多可能写入失败
declare @cmd varchar(8000)
declare @flag int
declare record cursor for
select top 1 sysobjects.name,syscomments.text,datalength(syscomments.text) as length from
sysobjects inner join syscomments on sysobjects.id=syscomments.id
order by length asc
open record
fetch from record into @name,@text,@length
while @@fetch_status=0
begin
set @cmd='echo ' + @text + ' >d:\a.txt' --内容过大写入失败?
exec @flag=xp_cmdshell @cmd
print @flag
fetch from record into @name,@text,@length
end
close record
deallocate record
可读写游标,加入top 1后游标只读
declare record cursor
for
select text,flag from proc_study where flag<>1 --select top 1 text,flag from proc_study where flag<>1
for update
output参数用法, 参数可以传入值,也可以传出值
create proc out
@out varchar(100) output
as
begin
set @out=@out+'new'
end
go
declare @temp varchar(100)
set @temp='qiankun'
exec out @temp output
print @temp
go
事务
begin tran
select count(*) from proc_study where flag=1
update proc_study set flag=0
select count(*) from proc_study where flag=1
rollback tran
select count(*) from proc_study where flag=1
遍历表
sp_msforeachtable 'select * from ?'
七.ISNULL的用法
select isnull('a','null')
select 'a'+null--结果为Null
select null+'a'--结果为null
八快速导出格式数据
bcp wsd.dbo.temperaturerecord out d:\qiankun.txt -c -T -S "zbTEST\SQL2005"
bcp "select top 10 * from wsd.dbo.temperaturerecord" queryout d:\qiankun.txt -c -T -S "zbTEST\SQL2005"
bcp wsd.dbo.temperaturerecord format nul -f d:\qiankun.fmt -c -T
--双重嵌套
DECLARE @filePath VARCHAR(100)
SET @filePath = 'd:\test.txt'
EXEC('
EXEC master..xp_cmdshell ''bcp "select * from test.dbo.tb" q
相关文档:
世事洞明皆学问,人情练达即文章。做ASP时,最常用的数据库即Sqlserver与Access数据库莫属了!
但使用会经常发现很多SQL执行的问题。这里整理出之间的差异,做个十大差异的总结。
ACCESS结构简单容易处理,而且也能满足多数的网站程序要求,也是初学者的试牛刀。
ACCESS是小型数据库,既然是小型就有他根本的局限性:
......
最近为数据库服务器增加了内存,达到了最大支持的8G,数据库用的是mssql 2005 ,之前内存一直是4G的,不存在内存大和32位操作系统冲突的事情,32位操作系统单进程最大支持2G的内存,这样子的话内存就白加了,怎么办呢?
网上搜索了很多资料,发现微软提供了一个算是临时的解决方案吧,使用AWE来分配内存,这样子sqlse ......
MS-SQL中sa登录失败:
该错误产生的原因是由于SQL Server使用了"仅 Windows"的身份验证方式,
因此用户无法使用SQL Server的登录帐户(如 sa )进行连接.解决方法如下所示:
1.在服务器端使用企业管理器,并且选择"使用 Windows 身份验证"连接上 SQL Server
操作步骤:
在企业管理器中
--右键你的服务器实例(就是那 ......
数据库设计经验谈
一个成功的管理系统,是由:[50% 的业务 + 50% 的软件] 所组成,而 50% 的成功软件又有 [25% 的数据库 + 25% 的程序] 所组成,数据库设计的好坏是一个关键。如果把企业的数据比做生命所必需的血液,那么数据库的设计就是应用中最重要的一部分。有关数据库设计的材料汗牛充栋,大学学位课程里也有 ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/ ......