isql实现数据库的部署、备份、恢复

环境:winXP+SQLServer2000

部署:

 bat文件: isql -Usa -ideploy.sql

sql文件:

restore database gboss from disk='D:\GBOSS\数据库备份\07-3-21' with file=1
go
IF SUSER_SID ('gboss') IS NULL
EXEC sp_addlogin 'gboss', 'gboss', @defdb='gboss'
go
use gboss
EXEC sp_grantdbaccess 'gboss', 'gboss'
go
EXEC sp_addrolemember 'db_owner', 'gboss'
go

备份:

bat文件: isql -Ugboss -Pgboss -ibackup.sql

sql文件:

--数据库备份
--命令isql -U -P -ibackup.sql
declare @fileName varchar(100)
set @fileName='D:\GBOSS\数据库备份\gboss_'+convert(varchar,getdate(),112)+'_'+replace(convert(varchar,getdate(),108),':','')
backup database gboss
to disk=@fileName
with description='backup'
print '已成功备份至'+@fileName

 

恢复:

bat文件: isql -Usa -irestore.sql
sql文件:

restore database gboss from disk='D:\GBOSS\数据库备份\07-3-21' with file=1

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

如果是在本地验证的话,可以采用-E参数,直接信任连接。

你可能感兴趣的:(sql,Go)