首页 > 编程技术 > php

MS SQL SERVER 图像或大文本的输入输出

发布时间:2016-11-25 16:42

在MS SQL SERVER 安装目录下有个可执行文件叫 TEXTCOPY.EXE
可对 MS SQL SERVER 中的文本或图像数据进行输入输出.
不过你可以在MS-DOS方式下执行textcopy /? 得到它的描述。
 
下面是这个工具的描述:
Copies a single text or image value into or out of SQL Server. The val
ue
is a specified text or image 'column' of a single row (specified by th
e
"where clause") of the specified 'table'.
If the direction is IN (/I) then the data from the specified 'file' is
copied into SQL Server, replacing the existing text or image value. If
the
direction is OUT (/O) then the text or image value is copied from
SQL Server into the specified 'file', replacing any existing file.
TEXTCOPY [/S ][sqlserver]] [/U [login]] [/P ][password]]
[/D ][database]] [/T table] [/C column] [/W"where clause"]
[/F file] [{/I | /O}] [/K chunksize] [/Z] [/?]
/S sqlserver The SQL Server to connect to. If 'sqlserver' is n
ot
specified, the local SQL Server is used.
/U login The login to connect with. If 'login' is not spec
ified,
a trusted connection will be used.
/P password The password for 'login'. If 'password' is not
specified, a NULL password will be used.
/D database The database that contains the table with the tex
t or
image data. If 'database' is not specified, the d
efault
database of 'login' is used.
/T table The table that contains the text or image value.
/C column The text or image column of 'table'.
/W "where clause" A complete where clause (including the WHERE keyw
ord)
that specifies a single row of 'table'.
/F file The file name.
/I Copy text or image value into SQL Server from 'fi
1.在要备份的数据上建立以下存储过程:
CREATE PROCEDURE [dbo].[过程名] AS
declare
@filename nvarchar(100),--文件名
@NowDay int --设置时间
set @filename='F:JXXdata' cast(Day(GetDate()) as varchar(2)) '.dat' --文件路径及文件名
Set @NowDay=Day(GetDate())
if (@NowDay>=20) or (@NowDay<=10) --这个月的20到下个月的10要备份
begin
print @filename BACKUP DATABASE [数据库名()你也可以设参数] TO DISK = @filename WITH INIT , NOUNLOAD , NAME = N'XX数据备份', NOSKIP , STATS = 10, NOFORMAT
end
存储过程要调试好无误
2、进入企业管理器中->管理->sql server代理->作业,新建作业,作业名称随便取,例如:data备份,所有者选择sa,当然你也可以选择其他用户,前提是该用户有执行作业的权限;
3.在步骤中取名-选中要备份的数据库 --在命令中输入 exec('过程名')
4.在调度中选反复出现--更改--选每天--时间自己输入
5.测试完后-最后导入脚本 进入服务器
6.把SQlServer服务管理器 启用SqlServer Agent服务


安装Oracle数据库后,当我们访问8080端口时,会弹出一个XDB窗口,要求输入用户名和密码。这样将和我们本地一些使用该端口的应用冲突,比如tomcat、jboss等,虽然这些端口是可以修改的,但总是不爽oracle一直占用这个端口。以下是我找到的一个方法,我已经试验成功了,如果你想用此法进行修改,请首先备份数据库重要内容,如果操作不慎,难免要重装数据库。
Oracle数据库可以使用TCP协议通过8080端口进行连接,所以占用了8080端口。
要取消占用,可以打开Oracle安装目录下的database目录内的SPFILE[SID名].ORA文件进行修改。这个文件是Oracle的启动配置文件。
把其中的*.dispatchers='(PROTOCOL=TCP) (SERVICE=or9iXDB)'这一行去掉即可。
然后重启计算机,或者在服务中重启OracleService[SID名]这个服务。重启后可能无法使用Enterprise Manager Console和其他客户端连接,这时请使用Oracle的Configuration and Migration Tools/Net Configuration Assistant工具删除监听器,然后新建一个监听器,重启监听器。
使用Configuration and Migration Tools/Net Manager工具,将服务命名删除,然后新建一个。
现在Oracle应该就可以正常使用,8080也不会占用了。


HAVING
用户在使用SQL语言的过程中可能希望解决的一个问题就是对由sum或其它集合函数运算结果的输出进行限制。例如,我们可能只希望看到Store_Information数据表中销售总额超过1500美圆的商店的信息,这时我们就需要使用HAVING从句。语法格式为:
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithematic function condition)
(GROUP BY从句可选)
由此,我们可以使用如下命令实现上述查询目的:
SELECT store_name, SUM(sales)
FROM Store_Information
GROUP BY store_name
HAVING SUM(sales) > 1500
查询结果显示为:
store_name SUM(Sales)
Los Angeles $1800
小注:
SQL语言中设定集合函数的查询条件时使用HAVING从句而不是WHERE从句。通常情况下,HAVING从句被放置在SQL命令的结尾处


其实只要使用系统内置的存储过程sp_spaceused就可以得到表的相关信息
如:sp_spaceused 'tablename'
以下是为了方便写的一个存储过程,目的是把当前的所有表的相关信息全部都保存在一个指定的表里面
CREATE PROCEDURE get_tableinfo AS

if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tablespaceinfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
create table tablespaceinfo --创建结果存储表
(nameinfo varchar(50) ,
rowsinfo int , reserved varchar(20) ,
datainfo varchar(20) ,
index_size varchar(20) ,
unused varchar(20) )


delete from tablespaceinfo --清空数据表

declare @tablename varchar(255) --表名称

declare @cmdsql varchar(500)

DECLARE Info_cursor CURSOR FOR
select o.name
from dbo.sysobjects o where OBJECTPROPERTY(o.id, N'IsTable') = 1
and o.name not like N'#%%' order by o.name

OPEN Info_cursor

FETCH NEXT FROM Info_cursor
INTO @tablename

WHILE @@FETCH_STATUS = 0
BEGIN

if exists (select * from dbo.sysobjects where id = object_id(@tablename) and OBJECTPROPERTY(id, N'IsUserTable') = 1)
execute sp_executesql
N'insert into tablespaceinfo exec sp_spaceused @tbname',
N'@tbname varchar(255)',
@tbname = @tablename

FETCH NEXT FROM Info_cursor
INTO @tablename
END

CLOSE Info_cursor
DEALLOCATE Info_cursor
GO


执行存储过程
exec get_tableinfo
查询运行该存储过程后得到的结果
select *
from tablespaceinfo
order by cast(left(ltrim(rtrim(reserved)) , len(ltrim(rtrim(reserved)))-2) as int) desc


标签:[!--infotagslink--]

您可能感兴趣的文章: