How to create a SQL Server 2008 database from a script

I am trying to do an Entity Framework walkthrough so that I:

  • uploaded the SQL script here: http://www.learnentityframework.com
  • in SQL Server Management Studio, I right-click Database, Create Database, name it
  • right click on the new database, New Query
  • clicked "Open file" and opened the script file: Create_ProgrammingEFDB1_SQLServer2008.sql
  • clicked "! Execute"
  • But the script (756K) has been running for 10 minutes and still says "Executing ..."

My questions:

  • Is this the standard way to read in a SQL script in SQL Server?
  • Is it supposed to take this long one ? So I would do it in MySQL / PHPMyAdmin, it may take a couple of seconds, so I assume that I am not doing something right.

Here is the beginning of the script, I changed the file paths to point to the desired .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 already created a database with the same name, so I tried to create a database that was already there, because of which it was hanging for some reason. I deleted this database, ran the script and successfully completed it in 3 seconds.

+6
sql-server
source share
2 answers

But script (756K)

It should be much more than just CREATE DATABASE in a script, so it is very difficult to tell when a script is doing.

You can record progress reports from the script back to the client, or use SQL Profiler to view the commands that are being executed.

+4
source share

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

Try adding the following to the script:

 SET STATISTICS TIME ON 

This will show the execution time of the queries when they are run, and it will help you more accurately identify the problem.

+5
source share

All Articles