日期:2014-05-17  浏览次数:20957 次

如何用asp恢复、创建数据库。已经有_data.mdf,_log.ldf
我现在已经有u_data.mdf和u_log.ldf。而且数据库u当中已经有数据。操作系统已经安装好sql   server2000,但是数据库当中没有建立u数据库。

请问如何用asp建立此数据库,同时保证u数据库能够正常运行。


谢谢!!!

------解决方案--------------------
CREATE TABLE 语句

语法
CREATE [TEMPORARY] TABLE表 (字段1类型 [(字长)] [NOT NULL] [WITH COMPRESSION | WITH COMP] [索引1] [, 字段2类型 [(字长)] [NOT NULL] [索引2] [, ...]][, CONSTRAINT multifieldindex [, ...]])

CREATE TABLE 语句分为以下几个部分:

部分 说明
table 欲创建的表的名称。
field1, field2 在新表中欲创建的字段的名称。至少必须创建一个字段。
type 在新表中的字段的数据类型。
size 字段的字符长度 (文本及二进制字段)。
index1, index2 子句定义多重字段索引的 CONSTRAINT 。
multifieldindex 子句定义多重字段索引的 CONSTRAINT 。
------解决方案--------------------
sp_attach_db
------解决方案--------------------
1、备份
<%
SQL= "backup database 数据库名 to disk= ' "&Server.MapPath( "backup ")& "\ "& "backuptext.dat "& " ' "
set cnn=Server.createobject( "adodb.connection ")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd= "
cnn.execute SQL
on error resume next
if err <> 0 then
response.write "错误: "&err.Descripting
else
response.write "数据备份成功! "
end if
%>

2、恢复
<%
SQL= "Restore database 数据库名 from disk= ' "&Server.MapPath( "backup ")& "\ "& "backuptext.dat "& " ' "
set cnn=Server.createobject( "adodb.connection ")
cnn.open "driver={SQL Server};Server=服务器名;uid=sa;pwd= "
cnn.execute SQL
on error resume next
if err <> 0 then
response.write "错误: "&err.Descripting
else
response.write "数据恢复成功! "
end if
%>
------解决方案--------------------
Jaron已经说得很清楚了.
附加上去.

至于其他备份/还原的可以不看.

------解决方案--------------------
EXEC sp_attach_db @dbname = N 'pubs ',
@filename1 = N 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf ',
@filename2 = N 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf '