Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/01/2009, 07:54
techno_mono
 
Fecha de Ingreso: diciembre-2008
Mensajes: 6
Antigüedad: 15 años, 6 meses
Puntos: 0
Pregunta duda con Restore script en SQLServer2000

hola amigos ota e me enfrento a un problema en mi practica...
Resulta que tengo un script que yo mismo escribi ayudado de un par de links en sn google

aca les dejo el codigo

-------------------------------------------------------------------------------------

Código:
declare @db_nom nvarchar(100), --NOMBRE DE LA BASE DE DATOS 
@ruta nvarchar(100), --RUTA A ARCHIVO .BAK 
@nom_data nvarchar(128), --NOMBRE DE ARCHIVO LOGICO DATA 
@nom_log nvarchar(128) --NOMBRE DE ARCHIVO LOGICO LOG 

set @db_nom="mi_base" 
set @ruta = "rutaackups" +@db_nom+ "BACKUP.bak" 

--CREACION TABLA TEMPORAL QUE GUARDA RESULTADOS DE FILELISTONLY 
create table #tableFileList 
(LogicalName nvarchar(128), 
PhysicalName nvarchar(260), 
Type char(1), 
FileGroupName nvarchar(128), 
Size numeric(20,0), 
MaxSize numeric(20,0)) 

--LLENADO DE #tableFileList 
insert into #tableFileList 
Exec("Restore Filelistonly From Disk="+ """" + @ruta + """") 

select @nom_data=(select logicalname from #tableFileList where type="D") 
select @nom_log=(select logicalname from #tableFileList where type="L") 

--RESTAURAR LA BASE DE DATOS 
exec("Restore database "+ @db_nom +" from 
disk=""" + @ruta + """ 
WITH MOVE """ + @nom_data + """ 
TO ""G:Program FilesMicrosoft SQL ServerMSS_intanciaData" + @nom_data + ".mdf"", 
MOVE """+ @nom_log +""" 
TO ""G:Program FilesMicrosoft SQL ServerMSS_intanciaData" + @nom_data + ".LDF"", 
REPLACE 
GO ") 

--CAMBIAR NOMBRES ARCHIVOS LOGICOS POR LOS CORRECTOS 
exec("ALTER DATABASE " + @db_nom + " 
MODIFY FILE( 
NAME = """ + @nom_log + """, 
NEWNAME =""" + @db_nom + "_log""") 

exec("ALTER DATABASE " + @db_nom + " 
MODIFY FILE( 
NAME = """ + @nom_data + """, 
NEWNAME =""" + @db_nom + "_data""") 

drop table #tableFileList
------------------------------------------------------------------------

Como ven el codigo es para la restauracion de bases de datos, este restaura el archivo backup.bak que se encuentra dentro de la carpeta con el nombre de la base de datos que le corrsponde.

Para una base de datos con nombre "mi_base" (@db_nom="mi_base") el codigo anterior me arroja el sgte error:

Código:
Server: Msg 170, Level 15, State 1, Line 8 
Line 8: Incorrect syntax near "GO". 
Server: Msg 170, Level 15, State 1, Line 4 
Line 4: Incorrect syntax near "mi_base_log". 
Server: Msg 170, Level 15, State 1, Line 4 
Line 4: Incorrect syntax near "mi_base_data".
no entiendo esos errores, ojala alguien me pueda ayudar

saludos