在SQLServer中怎么样恢复数据的存储?

 更新时间:2016年11月25日 16:44  点击:1386
在SQL Server中提供了这种恢复方式的存储过程。
一个数据库包括两个文件,mdf数据库文件和ldf日志文件
1.sp_attach_db [@dbname =] 'dbname',[@filename1 =] 'filename_n'
给系统添加一个数据库,在dbname指定数据库名称,filename_n指定数据库的文件和日志文件。比如我有一个ji的库,停止SQL Server服务备份ji_data.mdf,ji_log.ldf,启动SQL server,删除掉这个库,然后再把这两上文件拷到sql server DATA目录中,在Query Analyzer中执行如下语句:
EXEC sp_attach_db @dbname = N'ji',
@filename1 = N'd:mssql7dataji_data.mdf',
@filename2 = N'd:mssql7dataji_log.ldf'
就会把这个库加入到SQL Server Group中.

from: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6518
Connect/Read Remote SQL server Using PWS in win 98
I had to test Microsoft's Personal Webserver (PWS) in win 98 to access Remote SQL server 7.0
installed in a NT server. The clients to win 98 had LAN connections. Easy one , don't vote, have fun with
PWS. In fact I tested my connection with this script, before I created an out of process server demo with
VB.





code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!

Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in
compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the
original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or
code's description.

'**************************************
' Name: Connect/Read Remote SQL server U
' sing PWS in win 98
' Description:I had to test Microsoft's
' Personal Webserver (PWS) in win 98 to ac
' cess Remote SQL server 7.0 installed in
' a NT server. The clients to win 98 had L
' AN connections. Easy one , don't vote, h
' ave fun with PWS. In fact I tested my co
' nnection with this script, before I crea
' ted an out of process server demo with V
' B.
' By: Manas Mukherjee
'
如果你用的是sql server数据库!你不想用后台操作你可以看看这个
下面是对text的操作你可以看看
1. 写操作(WRITETEXT)
这里一般要用到的函数有TextPtr获得文本字段的指针,和TextVaild检验指针的有效性,@@RowCount判断返回记录的条数。
其基本方法是:用Textptr函数得到指针,判断其有效性,用Writetext写数据
函数说明:Textptr(字段名)。Writetext tablename。Fieldname @textptr(指针) [With Log] data(数据)
例如:
Begin Tran
Declare @Mytextptr VarBinary(16)
Select @mytextptr=textptr(pr_info)
From Pub_Info (updlock)
Where pud_id=’9999’
IF @Mytextptr Is Not Null
Writetext pub_info.pr_info @mytextptr with log 'data’
Commit Tran
2. 读操作
常用函数
PatIndex('%exp%’,var|fieldname。。)
Datalength()
@@TextSize 文本大小
SettextSize N 设置文本大小
ReadText {TableName。FieldName} {@textptr} Offet Size [HoldLock]
例如:
begin tran
Declare @mytextptr Varbinary(16),@Totalsize int,@Readsize int,@lastread int
Set textsize 100
Select @mytextptr=textptr(pr_info), @totalsize=datalength(pr_info)
@lastread=0,
@readsize= case when (textsize<datalength(pr_info) then textsize
eles datalength(pr_info)
end
From Pub_info
Where Pub_id=’1622’
IF @mytextptr Is not Null and @readsize>0
While (@lastread<@totalsize)
ReadText pub_info.pr_info @mytextptr @lastread @readsize holdlock
If (@@error<>0)
Break
Select @lastread=@lastread @readsize
If ((@readsize @lastread)>@totalsize)
Select @readsize=@totalsize-@lastread
End
Commit Tran
3.数据更新UpdateText
更新数据代替了写操作,其基本语法是:
UpdateText Table_Name.Col_Name Text_Ptr Offest(偏移量) Deleted_Length
[With Log] [Inserted_Data|Table_Name.Scr_Column_name Str_Text_Ptr]
说明:
Offest:0说明从开头开始,Null表示你向当前内容追加数据。
Deleted_Length:0表示不删除任何内容,Null表示删除所有内容。
解决SQL2k降序索引上使用对比条件更新或删除的bug我在SQL server 2000 enterprise 和 personal 都试过了, 每次都这样。:(
详细情况看我的回贴:
SQl server 7.0 中的确没有问题, sql 2000 中(enterprise 和 personal版本都可以),
表要有聚簇索引,并且索引的顺序是降序,
例如 按下列DDL sql 建立的表
CREATE TABLE [AType] (
[AID] [int] NOT NULL ,
[name] [varchar(20)] NOT NULL ,
CONSTRAINT [PK_DateType] PRIMARY KEY CLUSTERED
([AID] DESC) ON [PRIMARY] ,
) ON [PRIMARY]
添一些数据后, AID 分别分布在1-100之间
INSERT INTO [AType] VALUES(1,'a')
INSERT INTO [AType] VALUES(50,'b')
INSERT INTO [AType] VALUES(100,'c')

select from atype where Aid < 50
go
delete from Atype where AID < 50
go
select from atype where Aid < 50
最后一句查询仍然有记录输出. :(
by 怡红公子
报告已经发送给MSSQL开发小组,他们承认这一错误。
在没有新的补丁出来之前,给出以下建议:
不要在单列上使用降序索引,因为这并没有在性能上带来好处,仅仅是省略了Order by field desc几个字而已,用qa的show plan看一下就知道了,不管有没有order by或者不管是asc还是desc,都没有这项开销的(在聚簇索引上)。
降序索引一般是用于复合索引的,这可能是这个bug出现的原因。
原文:
Note that there is no need to create a descending index on a single column because SQL Server can traverse
an ascending index backwards when appropriate. Descending is normally used only in composite indexes.
This is probably why the bug surfaces here

正确的编译方法固然重要,但它只是提高MySQL服务器性能工作的一部分。MySQL服务器的许多参数会影响服务器的性能表现,而且我们可以把这些参数保存到配置文件,使得每次MySQL服务器启动时这些参数都自动发挥作用。这个配置文件就是my.cnf。
 
   MySQL服务器提供了my.cnf文件的几个示例,它们可以在/usr/local/mysql/share/mysql/目录下找到,名字分别为my-small.cnf、my-medium.cnf、my-large.cnf以及my-huge.cnf。文件名字中关于规模的说明描述了该配置文件适用的系统类型。例如,如果运行MySQL服务器的系统内存不多,而且MySQL只是偶尔使用,那么使用my-small.cnf配置文件最为理想,这个配置文件告诉mysqld daemon使用最少的系统资源。反之,如果MySQL服务器用于支持一个大规模的在线商场,系统拥有2G的内存,那么使用mysql-huge.cnf最为合适。
 
   要使用上述示例配置文件,我们应该先复制一个最适合要求的配置文件,并把它命名为my.cnf。这个复制得到的配置文件可以按照如下三种方式使用:
全局:把这个my.cnf文件复制到服务器的/etc目录,此时文件中所定义的参数将全局有效,即对该服务器上运行的所有MySQL数据库服务器都有效。
 
局部:把这个my.cnf文件复制到[MYSQL-INSTALL-DIR]/var/将使该文件只对指定的服务器有效,其中[MYSQL-INSTALL-DIR]表示安装MySQL的目录。
 
用户:最后,我们还可以把该文件的作用范围局限到指定的用户,这只需把my.cnf文件复制到用户的根目录即可。
 
   那么,如何设置my.cnf文件中的参数呢?或者进一步说,哪些参数是我们可以设置的呢?所有这些参数都对MySQL服务器有着全局性的影响,但同时每一个参数都和MySQL的特定部分关系较为密切。例如,max_connections参数属于mysqld一类。那么,如何才能得知这一点呢?这只需执行如下命令:
% >/usr/local/mysql/libexec/mysqld --help

   该命令将显示出和mysqld有关的各种选项和参数。要寻找这些参数非常方便,因为这些参数都在“Possible variables for option --set-variable (-O) are”这行内容的后面。找到这些参数之后,我们就可以在my.cnf文件中按照如下方式设置所有这些参数:
set-variable = max_connections=100

   这行代码的效果是:同时连接MySQL服务器的最大连接数量限制为100。不要忘了在my.cnf文件[mysqld]小节加上一个set-variable指令,具体请参见配置文件中的示例
[!--infotagslink--]

相关文章