Edward Tanguay
Edward Tanguay

Reputation: 193302

How to create an SQL Server 2008 database from script

I'm trying to do an Entity Framework walkthrough so I:

My questions are:

Here is the beginning of the script, I changed the file paths so they point to the right .mdf and .ldf files:

****/

--PART ONE  CREATE THE DATABASE. Note the file paths in the first few commands. 
--Change them for your own computer.--
USE [master]
GO

    /****** Object:  Database [ProgrammingEFDB1]    Script Date: 01/28/2009 10:17:44 ******/
    CREATE DATABASE [ProgrammingEFDB1] ON  PRIMARY 
    ( NAME = N'ProgrammingEFDB1', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\ProgrammingEFDB1.mdf' , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
     LOG ON 
    ( NAME = N'ProgrammingEFDB1_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\ProgrammingEFDB1_log.LDF' , MAXSIZE = UNLIMITED, FILEGROWTH = 10%)
    GO

    ALTER DATABASE [ProgrammingEFDB1] SET COMPATIBILITY_LEVEL = 90
    GO

    IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
    begin
    EXEC [ProgrammingEFDB1].[dbo].[sp_fulltext_database] @action = 'disable'
    end
    ...

ANSWER:

I had already created a database with the same name so it was trying to create a database that was already there which made it hang for some reason. I deleted that database, reran the script and it completed successfully in 3 seconds.

Upvotes: 6

Views: 52230

Answers (2)

Quassnoi
Quassnoi

Reputation: 425371

I don't know what does your script do exactly in the next 754K, but the lines you posted seem quite harmless.

Try adding the following to your script:

SET STATISTICS TIME ON

This will show queries execution times as they run, and it will help you to locate the problem more exactly.

Upvotes: 5

Richard
Richard

Reputation: 108995

But the script (756K)

Must be a lot more than just a CREATE DATABASE in the script, so very hard to say when the script is doing.

You can write progress reports from the script back to the client, or use SQL Profiler to see what commands are being executed.

Upvotes: 4

Related Questions