Reputation: 17368
I have an SQL file which I am executing on an SQL Server instance which contains the schema for a database. The file creates a brand new database (as in, a database with this name does not exist on this server):
CREATE DATABASE PROJECT;
and begins to create a relation:
CREATE TABLE Courses (
CourseID INT NOT NULL PRIMARY KEY,
Name VARCHAR(64) NOT NULL UNIQUE,
Code CHAR(4) NOT NULL UNIQUE
);
...
and here is what SQL Server tells me right off the bat:
Msg 2714, Level 16, State 6, Line 3
There is already an object named 'Courses' in the database.
Any idea why SQL Server tells me that there already exists a relation by the name of Courses
when clearly there isn't?
Thank you for your time.
Upvotes: 3
Views: 10541
Reputation: 160
Long shot but try using:
Use project;
CREATE TABLE Courses....
Upvotes: 0
Reputation: 263933
Check the database if you are using PROJECT
CREATE DATABASE PROJECT
GO
USE PROJECT
GO
CREATE TABLE Courses
(
CourseID INT NOT NULL PRIMARY KEY,
Name VARCHAR(64) NOT NULL UNIQUE,
Code CHAR(4) NOT NULL UNIQUE
)
GO
Upvotes: 5
Reputation: 1756
You are likely missing USE PROJECT
statement and therefore trying to create Courses table in the master database, not in the PROJECT database.
Upvotes: 3