Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

T-SQL question

Status
Not open for further replies.

ccampbell

Programmer
Aug 16, 2001
201
US
WHy does this not work? It removes the old database and creates a new one with all the specks that I specify, but when I do the restore, it does not restore any of my old tables. Any ideas? it restores all of the sys... tables but none of my backed up tables.
-- ========================================
-- Used to delete the old Database
-- ========================================
IF EXISTS (SELECT *
FROM master..sysdatabases
WHERE name = N'CVIEW')
DROP DATABASE CVIEW
GO

-- ==================
-- Create Database
-- ==================
USE master
GO
CREATE DATABASE CVIEW
ON
( NAME = 'CVIEW_dat',
FILENAME = 'c:\program files\microsoft sql server\mssql\data\CVIEW.mdf',
SIZE = 2000MB,
FILEGROWTH = 10% )
LOG ON
( NAME = 'CVIEW_log',
FILENAME = 'c:\program files\microsoft sql server\mssql\data\CVIEW.ldf',
SIZE = 2000MB,
FILEGROWTH = 10% )
GO

-- =====================
-- Restore Database
-- =====================
USE master
GO
-- First determine the number and names of the files in the backup.
RESTORE FILELISTONLY
FROM DISK = N'c:\xCVIEWbackup.dbk'

-- Restore the files for new Db.
RESTORE DATABASE CVIEW
FROM DISK = N'c:\xCVIEWbackup.dbk'
WITH REPLACE

GO
 
Are you sure that was a good backup? What happens when you try to restore the same backup through enterprise manager?
 
I actually fixed my problem ...I think. It is a good backup and when I restore it through EnterPrise Manager it restores fine. I have narrowed it down to the lines USE master. If I run the above SQL commands excluding the USE master, it creates the database just fine with all the tables and the data. Is USE master necessary, or can remove those and still be okay. Thanks for the speedy reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top