After creating tables, relationships, primary keys, and foreign keys in an entit
ID: 3580005 • Letter: A
Question
After creating tables, relationships, primary keys, and foreign keys in an entity relationship diagram in SQL management studio 2012. I need to create table and insert statements. When I try to create Create Table statements i get an error.
Here is the code for the employee table i have.
USE [Human Resources (HR) Department]
GO
/****** Object: Table [dbo].[employee] Script Date: 12/12/2016 7:22:19 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[employee](
[emp_id] [int] NOT NULL,
[first_name] [nchar](20) NOT NULL,
[last_name] [nchar](20) NOT NULL,
[e_mail] [nchar](20) NOT NULL,
[hire_date] [nchar](20) NOT NULL,
CONSTRAINT [PK_employee] PRIMARY KEY emp_id
(
[emp_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
Here is the error im getting :
Msg 2714, Level 16, State 6, Line 2
There is already an object named 'employee' in the database.
I created 4 tables in the entity relationship diagram and one of them is an employee table. I know this sounds confusing so im going to put the directions i have on the assignment.
1. Create A normalized database consisting of
An Entity-Relationship Diagram that shows the table names, column names, and keys (primary and foreign – it is ok to not label the foreign keys if it is clear by the column names what your foreign keys are).
A set of CREATE TABLE and INSERT statements that properly populate the database.
Your CREATE TABLE statements should include primary and foreign key constraints.
Make sure that these statements are in the right order and that they execute.
My question is this. Should i go straight to the insert statements in a new query since it seems to me that i have already created the create table statements, primary and foreign keys in the entity relationship diagram.
Explanation / Answer
Dear Student,
It seems to me that you have created other tables other than an employee table.
Now, This error says that Employee table already exists in your database. You can not create a table with the same name.
To solve this problem. You can use employee table already available in your database but make sure that employee table has all columns which are required by you. If all columns are not available in employee table. You can add it using below command.
Alter table <table-name{employee}>
add column <column-name> <data-type>.
And yes, you should go straight to the insert statements in a new query.
Best Luck..!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.