views:

321

answers:

4

I have following script. I dont know how to create new database in sql server 2005. I run following scirpt, and it create tables under model instead of seperate databse. it look massy.

how can i create seperate databse. I am copy some script here for your adive and course of action.

-----------------------------------------------------------
-- SQL Server 2000 Bible 
-- Hungry Minds 
-- Paul Nielsen

-- OBX Kites sample database - CREATE Database, Tables, and Procs

-- this script will drop an existing OBXKites database 
-- and create a fresh new installation

-- related scripts:
-- OBXKites_Populate

-- T-SQL KEYWORDS go
-- DatabaseNames   

-----------------------------------------------------------
-----------------------------------------------------------
-- Drop and Create Database


USE master
GO
IF EXISTS (SELECT * FROM SysDatabases WHERE NAME='OBXKites')
  DROP DATABASE OBXKites
go

-- This creates 1 database that uses 2 filegroups
CREATE DATABASE OBXKites
  ON PRIMARY
    (NAME = 'OBXKites', FILENAME = 'D:\SQLData\OBXKites.mdf'),
  FILEGROUP Static
    (NAME = 'OBXKitesStatic', FILENAME = 'c:\SQLData\OBXKitesStatic.ndf')
  LOG ON (NAME = 'OBXKitesLog',  FILENAME = 'c:\SQLData\OBXKites.ldf')
go

-- set to Full Log

go

SET QUOTED_IDENTIFIER ON
go
USE OBXKites
go

-----------------------------------------------------------
-----------------------------------------------------------
-- Create Tables, in order from primary to secondary

CREATE TABLE dbo.OrderPriority (
  OrderPriorityID UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL DEFAULT (NEWID()) PRIMARY KEY NONCLUSTERED,
  OrderPriorityName NVARCHAR (15) NOT NULL,
  OrderPriorityCode NVARCHAR (15) NOT NULL,
  Priority INT NOT NULL
  )
  ON [Static]
go
A: 

Are there any errors in output? The script itself does already do what you requested.

I'd suspect that you incorrectly specified filenames - some of them are on drive C:, and some on drive D:.

queen3
A: 

Your script in question will create the tables in the OBXKites database (see the USE OBXKites statement in your script)

Does the OBXKites database already exist in your server instance? If so, that's probably why it appears that it is creating the tables in the current database, since the script is effectively removing and recreating the OBXKites database. If you need a different name for the database, find all instances of "OBXKites" in your script above after the line that reads "This creates 1 database that uses 2 filegroups" and rename it to the new database name you desire.

The only other option could be that the script has execution errors creating the database, if your user account lacks the proper permissions to do so. However, the script continues to execute, creating the tables in the current database you are logged in to, which is why you are seeing the tables there.

Dillie-O
A: 

Can you simplify it down? or do you have to do all of that checking?

If it can be simplified I beileve some code such as:

CREATE DATABASE OBXKites

USE OBXKites

CREATE TABLE OrderPriority(syntax)

If simple code like this doesn't work, you may have deeper issues with rights or files or something as suggested by queen3 just before me.

Afterthought: At my school we were having issues like this as well I believe... after a few classes we finally arived at the conclusion that we didn't have rights to add files to the program files directory on the lab computers and SQL wasn't reporting the error to us.

Jrud
+3  A: 
CREATE DATABASE OBXKites
ON PRIMARY
     (NAME = 'OBXKites', FILENAME = 'D:\SQLData\OBXKites.mdf'),  
   FILEGROUP Static
     (NAME = 'OBXKitesStatic', FILENAME = 'c:\SQLData\OBXKitesStatic.ndf')
LOG ON 
   (NAME = 'OBXKitesLog',  FILENAME = 'c:\SQLData\OBXKites.ldf')
go

This code in your script should create a new database. If no error occurrs in the process.

j.a.estevan
I understand. can you also explain me filename thing in above script.
Novice Developer
This tells sql server where to locate the database files. In this case it is creating two database files for data an one for log (transactions). Usualy there will be only 2 files for small-medium databases.You can delete this piece of code and the files will be alocated in the default directory for the server. You can move this files later if you want/need to. In your code, it will work only with the first sentence I quoted.
j.a.estevan
But what is problem with create table. I am still getting filegroup error.
Novice Developer
It would be helpful if you post the complete error. I'm prety sure you are looking for the error in the wrong way. May be the database is not being created for an external problem (security, permisions, ...).
j.a.estevan
it is solved now. I removed ON [STATIC] from tables. it is working..thank you.
Novice Developer