如何减小SqlServer数据库文件大小

分两个部分:

1.log 文件,ldf.对老的sql server版本,用

BACKUP LOG BlogEngine WITH TRUNCATE_ONLY

如果新版的不支持该命令,用

BACKUP LOG BlogEngine TO DISK = ‘NUL:’

替代,参考来源是这里

但是这样缩小的log文件不会小于其初始尺寸,这个可以在管理工具里调整,应该也有命令行,懒得查了。

log size   2.主文件,mdf。 DBCC SHRINKDATABASE (数据库名,TRUNCATEONLY), Releases all free space at the end of the file to the operating system but does not perform any page movement inside the file. The data file is shrunk only to the last allocated extent. DBCC SHRINKDATABASE (数据库名,10),把空余的文件内部空间释放到仅留10%的待增长空间。 参考:微软官方文档

oracle里的空字符串是null吗?

http://stackoverflow.com/questions/203493/why-does-oracle-9i-treat-an-empty-string-as-null

再看我们的数据库,都是varchar2类型的,默认值是‘ ’(有空格),但又是nullable的。所以再要排除空记录(包括空值和默认值),应该是

XXX is not null and xxxx <> ‘ ’(有空格) 或者 nvl(xxx,‘ ’)<> ‘ ’

后则写起来简单一些。

update:

经试验,这种做法比较简洁(必较即要判断 is null,又要判断一个空格的做法)

trim(XXX) is null

当XXX是空格或是null值(空串)的时候都成立

不为空就则改成is not null

比如

select  sop_destination_warehouse from SALES_ORDER_HEADERS where trim(sop_destination_warehouse) is null 返回的是sop_destination_warehouse为空的记录

select  sop_destination_warehouse from SALES_ORDER_HEADERS where trim(sop_destination_warehouse) is  not null 返回的是sop_destination_warehouse有值的记录。

另:安装ODP.net可以解决System.Data.OracleClient   requires   Oracle   client   software   version   8.1.7   or   greater.的错误。并且,要给予aspnet账号(iis5.1,其他版本看具体服务进程的用户)oracle client目录读写权限。