Why am I getting this constraint error when I try and run my ETL? Using SQL serv
ID: 3700253 • Letter: W
Question
Why am I getting this constraint error when I try and run my ETL? Using SQL server
When I create my DwPubsSales database these are the FK's I coded in
/****** Add Foreign Keys ******/
Alter Table [dbo].[DimTitles] With Check Add Constraint [FK_DimTitles_DimPublishers]
Foreign Key ([PublisherKey]) References [dbo].[DimPublishers] ([PublisherKey])
Alter Table [dbo].[FactTitlesAuthors] With Check Add Constraint [FK_FactTitlesAuthors_DimAuthors]
Foreign Key ([AuthorKey]) References [dbo].[DimAuthors] ([AuthorKey])
Alter Table [dbo].[FactTitlesAuthors] With Check Add Constraint [FK_FactTitlesAuthors_DimTitles]
Foreign Key ([TitleKey]) References [dbo].[DimTitles] ([TitleKey])
Go
Alter Table [dbo].[FactSales] With Check Add Constraint [FK_FactSales_DimStores]
Foreign Key ([StoreKey]) References [dbo].[DimStores] ([Storekey])
Go
Alter Table [dbo].[FactSales] With Check Add Constraint [FK_FactSales_DimTitles]
Foreign Key ([TitleKey]) References [dbo].[DimTitles] ([TitleKey])
Go
Alter Table [dbo].[FactSales] With Check Add Constraint [FK_FactSales_DimDates]
Foreign Key ([OrderDateKey]) References [dbo].[DimDates] ( [DateKey] )
Go
Alter Table [dbo].[DimTitles] With Check Add Constraint [FK_DimTitles_DimDates]
Foreign Key ([PublishedDateKey]) References [dbo].[DimDates] ( [DateKey] )
Then in my ETL I am trying to flush, and in my first step I am getting an error
-- First drop all foreign key constraints
ALTER TABLE dbo.DimTitles DROP CONSTRAINT [FK_DimTitles_DimPublishers]
ALTER TABLE dbo.DimTitles DROP CONSTRAINT [FK_DimTitles_DimDates]
ALTER TABLE dbo.FactSales DROP CONSTRAINT [FK_FactSales_DimTitles]
ALTER TABLE dbo.FactSales DROP CONSTRAINT [FK_FactSales_DimStores]
ALTER TABLE dbo.FactSales DROP CONSTRAINT [FK_FactSales_DimDates]
Go
When I run this I get the error:
Msg 3728, Level 16, State 1, Line 1
'FK_DimTitles_DimPublishers' is not a constraint.
Msg 3727, Level 16, State 0, Line 1
Could not drop constraint. See previous errors.
Which is refering to this line here: ALTER TABLE dbo.DimTitles DROP CONSTRAINT [FK_DimTitles_DimPublishers]
But I don't understand why its sayign this when the database was created fine.
Explanation / Answer
Answer
ALTER TABLE dbo.DimTitles DROP CONSTRAINT [FK_DimTitles_DimPublishers]
Go
ALTER TABLE dbo.DimTitles DROP CONSTRAINT [FK_DimTitles_DimDates]
Go
ALTER TABLE dbo.FactSales DROP CONSTRAINT [FK_FactSales_DimTitles]
Go
ALTER TABLE dbo.FactSales DROP CONSTRAINT [FK_FactSales_DimStores]
Go
ALTER TABLE dbo.FactSales DROP CONSTRAINT [FK_FactSales_DimDates]
Go
--------------------------------------------------------------------------------
Given below a sample working ScreenShot
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.