0

I'm trying to do a simple a database SQL script where I simply need tocreate a database as well as 4 tables within. So far I'm getting a very annoying error that states: There is already an object named 'DEVICE_TYPE' in the database. Why, I don't know? Any help regarding this matter will be highly appreciated.

Please see the code below:

DROP Database EliteShop
GO

CREATE Database EliteShop
GO

USE EliteShop
GO

CREATE TABLE DEVICE_TYPE
(
    Device_TypeID INT IDENTITY(1,1),
    Device_TypeID_Name VARCHAR(50),
    CONSTRAINT pk_devicetype PRIMARY KEY(Device_TypeID)
)

CREATE TABLE MANUFACTURER
(
    Manufacturer_Code VARCHAR(50),
    Manufacturer_Description VARCHAR(100),
    CONSTRAINT pk_manufacturercode PRIMARY KEY(Manufacturer_Code)
)

CREATE TABLE [PLATFORM]
(
    PlatformID INT IDENTITY(1,1),
    Platform_Description VARCHAR(50),
    CONSTRAINT pk_platID PRIMARY KEY(PlatformID)
)

CREATE TABLE DEVICE
(
    DeviceID INT IDENTITY(1,1),
    Device_TypeID INT,
    PlatformID INT,
    Manufacturer_Code VARCHAR(50),
    Model VARCHAR(50),
    InternalMemory VARCHAR(10),
    Price MONEY,
    CONSTRAINT pk_deviceID PRIMARY KEY (DeviceID),
    CONSTRAINT fk_deviceType FOREIGN KEY (Device_TypeID) REFERENCES DEVICE_TYPE(Device_TypeID),
    CONSTRAINT fk_manuFCode FOREIGN KEY (Manufacturer_Code) REFERENCES MANUFACTURER(Manufacturer_Code),
    CONSTRAINT fk_myPlatID FOREIGN KEY (PlatformID) REFERENCES [PLATFORM](PlatformID)
)
4
Contributors
4
Replies
23
Views
2 Years
Discussion Span
Last Post by erikko
0

DeviceType isn't showing the list of reserved words for SQL Server but it does seem to be a named enumeration in SQL Server 2012/14. You might want to use a different name for that table in case it is conflicting with SQL Server internal structure.

0

Hi

I tried your script, first time I had to omit the DROP EliteShop statement as that did not exist (of course) and it ran fine. I then put the DROP EliteShop back in and ran the statement and again, it ran fine. I am running SQL Server 2014.

I know my answer is not much help, I'm not quite sure why it would not be working as I don't see anything wrong with the script.

0

Hey guys,

well I managed to find a solution. I just deleted the database after I created it the first time. (Sounds weird and redundent) but when I ran the script again afterwards and it worked... Was maybe just a weird error or something.

But I assume when you run the script once you shouldnt run it again then it will give you the error that the tables already exists... So I understand what I did wrong.

Thanks for your help! :)

Joe

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.