Drop table if exists, MSSQL, Part 2

Hi Expert,

This is a continuation from my last post... I am trying to create a table using the following code

/*Agent's commission rates*/

USE CSS_Reservations;

/*Drop and Create MySQL-formatted table*/
IF OBJECT_ID( N'dbo.agent_rates' ) IS NOT NULL
	DROP TABLE dbo.agent_commissions;

CREATE TABLE dbo.agent_commissions
	(agent_id INT NOT NULL , product_id VARCHAR(6) NOT NULL , 
	 family DECIMAL(5,2) NOT NULL , adult DECIMAL(5,2) NOT NULL , senior DECIMAL(5,2) NOT NULL ,
	 student DECIMAL(5,2) NOT NULL , child DECIMAL(5,2) NOT NULL , infant DECIMAL(5,2) NOT NULL);

Open in new window

But I keep getting
Msg 2714, Level 16, State 6, Line 9
There is already an object named 'agent_commissions' in the database.

However, isn't this taken care of on lines 6-7?

Thank you
APD TorontoAsked:
Who is Participating?
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
IF OBJECT_ID( N'dbo.agent_rates' ) IS NOT NULL
      DROP TABLE dbo.agent_commissions;

So ... if agent_rates exists, drop agent_commissions?   Is this a typo, and should be...

IF OBJECT_ID( N'dbo.agent_commissions' ) IS NOT NULL
      DROP TABLE dbo.agent_commissions;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.