Trying to figure out CONSTRAINT error in SQl 2008

I am workign through some tutorials and I am now stumepd as to how I can resolve my issue I am having.
Here is my Query:
USE SQL2008SBS
GO

--Must drop foreign key first, because it depends on the primary key
OrderDetail
    DROP CONSTRAINT fk_orderheadertoorderdetails
GO
 
--Change the existing primary keys to nonclustered
ALTER TABLE Orders.OrderHeader
    DROP CONSTRAINT pk_orderheader
GO
ALTER TABLE Orders.OrderHeader
    ADD CONSTRAINT pk_orderheader PRIMARY KEY NONCLUSTERED (OrderID)
GO
ALTER TABLE Orders.OrderDetail
    DROP CONSTRAINT pk_orderdetail
GO
ALTER TABLE Orders.OrderDetail
    ADD CONSTRAINT pk_orderdetail PRIMARY KEY NONCLUSTERED (OrderDetailID)
GO
--Recreate the foreign key (fix the misspelling from chapter 5)
ALTER TABLE Orders.OrderDetail
    ADD CONSTRAINT fk_orderheadertoorderdetails FOREIGN KEY (OrderID)
    REFERENCES Orders.OrderHeader (OrderID)    
GO
--Create new clustered indexes on the ShipDate/FinalShipDate columns
CREATE CLUSTERED INDEX icx_finalshipdate ON Orders.OrderHeader (FinalShipDate)
GO
CREATE CLUSTERED INDEX icx_shipdate ON Orders.OrderDetail (ShipDate)
GO

Here is my error:

Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'CONSTRAINT'.
Msg 3725, Level 16, State 0, Line 3
The constraint 'pk_orderheader' is being referenced by table 'OrderDetail', foreign key constraint 'fk_orderheadertoorderdetails'.
Msg 3727, Level 16, State 0, Line 3
Could not drop constraint. See previous errors.
Msg 1779, Level 16, State 0, Line 1
Table 'OrderHeader' already has a primary key defined on it.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
Msg 2714, Level 16, State 4, Line 2
There is already an object named 'fk_orderheadertoorderdetails' in the database.
Msg 1750, Level 16, State 0, Line 2
Could not create constraint. See previous errors.
Msg 1902, Level 16, State 3, Line 2
Cannot create more than one clustered index on table 'Orders.OrderHeader'. Drop the existing clustered index 'pk_orderheader' before creating another.
Msg 1913, Level 16, State 1, Line 1
The operation failed because an index or statistics with name 'icx_shipdate' already exists on table 'Orders.OrderDetail'.
manelson05Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
this:
--Must drop foreign key first, because it depends on the primary key
OrderDetail
    DROP CONSTRAINT fk_orderheadertoorderdetails

should be:

--Must drop foreign key first, because it depends on the primary key
ALTER TABLE OrderDetail
    DROP CONSTRAINT fk_orderheadertoorderdetails
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
manelson05Author Commented:
Rockin!

Sorry for the delay I have another I am going to psot soon.

thanks!

mark
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.