August 10, 2012 at 2:45 am
Dear Sir,
After creating script from database in MS SQL server 2008,if we want to run all the database in other PC,then we can crate Database using SQL script in SQL server.
In reverse order to create database from given script.
How to create the SQL Database from SQL script in MS SQL server 2008.
Please give steps or links.
August 10, 2012 at 2:48 am
If I understand correctly, you want to look at the CREATE DATABASE command.
August 10, 2012 at 4:54 am
Thank you sir for your reply.
Now I have tried SQL create command to create Database from given sql script.
I have tried as follows:
-------------------------------------------------
Create DATABASE [datauwatchit]
ON PRIMARY
( NAME = N'datauwatchit', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\dbuwatchit.mdf' , SIZE = 5120KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'datauwatchit', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\dbuwatchit_log.ldf' , SIZE = 2048KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
-----------------------------------------------
Error is as follows:
Msg 1828, Level 16, State 5, Line 1
The logical file name "datauwatchit" is already in use. Choose a different name.
==========================================================
So I have tried Alter command to solve above errror
------------------------------------------------
ALTER DATABASE [$(datauwatchit)]
ADD FILE
(
NAME = [$(dbuwatchit)],
FILENAME = '$(C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\datauwatchit.mdf)$(datauwatchit).mdf',
SIZE = 10 MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 5 MB
)
TO FILEGROUP [PRIMARY];
------------------
Error is as follows:
Msg 911, Level 16, State 1, Line 1
Database '$(datauwatchit)' does not exist. Make sure that the name is entered correctly.
=====================
Please reply where is problem and how to solve in code.
August 10, 2012 at 4:59 am
First error is, a database is already using the logical filename. So I am guessing you already have the database created.
The other error in the ALTER is that you have $ in there, remove the $.
August 10, 2012 at 5:18 am
Hello Sir,
When I execute Create Database script then error is Database is already exist so after I execute ALTER Databse script then error is database does not exist.
I have SQL script from which I have to create whole database with tables.
When I execute only Create Database[Name] then database is created but Tables are not there in the database.
Currently I have inserted CREATE DATABASE code in the .sql script to create Database with tables so this way is true or wrong? Should I try any other method?
So please guide me.
August 10, 2012 at 5:21 am
Your first error that database already exists, is because you already have a database with that name.
Drop the existing database or change the name of the database in your script.
The error in the ALTER DATABASE command is that the database doesnt exist, because it is looking for a database with a name of $(datauwatchit) and you dont have a database whos name is this.
The CREATE DATABASE script is fine and will work, you just cannot have the same database multiple times.
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy