Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Script not creating database correctly
Message
De
26/02/2013 19:17:46
 
 
À
26/02/2013 13:58:41
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Scripting
Divers
Thread ID:
01566939
Message ID:
01566998
Vues:
51
>>>>>>Hi All
>>>>>>
>>>>>>We're trying to transfer a database from one server to another and had SQL create the script to do so. Unfortunately, it's creating the tables within the Master database and not within the new database. In fact, it's not even creating the new database. Here's the script that was generated, could someone point out why it's not doing what it's supposed to do?
>>>>>>
>>>>>>USE [master]
>>>>>>GO
>>>>>>/****** Object:  Database [DLI_Testing]    Script Date: 02/26/2013 06:41:26 ******/
>>>>>>CREATE DATABASE [DLI_Testing] ON  PRIMARY 
>>>>>>( NAME = N'DLI_Testing', FILENAME = N'D:\DLI_Testing.mdf' , SIZE = 78080KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
>>>>>> LOG ON 
>>>>>>( NAME = N'DLI_Testing_log', FILENAME = N'D:\DLI_Testing_log.LDF' , SIZE = 470144KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
>>>>>>GO
>>>>>>ALTER DATABASE [DLI_Testing] SET COMPATIBILITY_LEVEL = 100
>>>>>>GO
>>>>>>IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
>>>>>>begin
>>>>>>EXEC [DLI_Testing].[dbo].[sp_fulltext_database] @action = 'enable'
>>>>>>end
>>>>>>GO
>>>>>>
>>>>>
>>>>>
>>>>>Any error messages?
>>>>
>>>>Oh, lord, yes - here's the top part
>>>>
>>>>Msg 5170, Level 16, State 1, Line 2
>>>>Cannot create file 'D:\DLI_Testing.mdf' because it already exists. Change the file path or the file name, and retry the operation.
>>>>Msg 1802, Level 16, State 4, Line 2
>>>>CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
>>>>Msg 5011, Level 14, State 5, Line 1
>>>>User does not have permission to alter database 'DLI_Testing', the database does not exist, or the database is not in a state that allows access checks.
>>>>Msg 5069, Level 16, State 1, Line 1
>>>>ALTER DATABASE statement failed.
>>>>
>>>
>>>These messages say all.
>>>You have already a file named DLI_Testing.mdf in D:\ drive.
>>>Maybe you can't see this DB because you didn't refresh Object Explorer in SSMS?
>>>Also you may have a DB with different name that uses this file.
>>>
>>>Run this:
>>>
>>>SELECT Name, FileName FROM sysdatabases WHERE FileName LIKE '%DLI_Testing%'
>>>
>>>
>>>Also, when you create the script ALWAYS set "Include if NOT EXISTS" to true (check the attached image).
>>
>>Possible the file is detached so wont show up in SSMS. Try attaching it. Then run the rest of the script.
>>
>>If the goal is just to copy the database to another server why not just detach, copy and reattach on the other server. Sometimes on a one-shot deal like this it is easier to do it manually than to figure out why the script is complaining.
>
>These are on separate servers. Completely separate servers - as in we sneaker-net the files across - and since this is not the only time we're going to have to do this, we need to figure out what's going on. The joys of having no DBA

This is the most popular answer on Stackoverflow : ( and having done this myself many times I know it works ) What does this not accomplish that you need accomplished?

Right-click on the Database, select Tasks and then Generate Scripts, which will launch the Script Wizard. This allows you to generate a single script that can recreate the full database including table/indexes & constraints/stored procedures/functions/users/etc. There are a multitude of options that you can configure to customise the output, but most of it is self explanatory.

If you are happy with the default options, you can do the whole job in a matter of seconds.

If you want to recreate the data in the database (as a series of INSERTS) I'd also recommend SSMS Tools Pack (Free for SQL 2008 version, Paid for SQL 2012 version).


Charles Hankey

Though a good deal is too strange to be believed, nothing is too strange to have happened.
- Thomas Hardy

Half the harm that is done in this world is due to people who want to feel important. They don't mean to do harm-- but the harm does not interest them. Or they do not see it, or they justify it because they are absorbed in the endless struggle to think well of themselves.

-- T. S. Eliot
Democracy is two wolves and a sheep voting on what to have for lunch.
Liberty is a well-armed sheep contesting the vote.
- Ben Franklin

Pardon him, Theodotus. He is a barbarian, and thinks that the customs of his tribe and island are the laws of nature.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform