I've build a partitioned view against a set of tables with sperated by month using a a partioning field of datetime.
The partitioned view apears to work perfectly with inserts and selects until I've performed a "BULK INSERT" into one or more of the partitioned tables. After that if I attempt an INSERT into the view I receive the error:
UNION ALL view 'transaction_log' is not updatable because a partitioning column was not found.
The following queries are used to create the tables and partition view.
CREATE TABLE [dbo].[transaction_log_20050101] (
[merchant_id] [int] NOT NULL ,
[id] [int] NOT NULL ,
[trn_datetime] [datetime] NOT NULL CHECK ([trn_datetime] < cast('2/1/2005'
as datetime)),
[trn_value] [varchar] (32) NOT NULL)
ALTER TABLE [dbo].[transaction_log_20050101] ADD PRIMARY KEY
(
[trn_datetime],
[merchant_id],
[id]
)
CREATE TABLE [dbo].[transaction_log_20050201] (
[merchant_id] [int] NOT NULL ,
[id] [int] NOT NULL ,
[trn_datetime] [datetime] NOT NULL CHECK ([trn_datetime] >= cast('2/1/2005'
as datetime) AND [trn_datetime] < cast('3/1/2005' as datetime)),
[trn_value] [varchar] (32) NOT NULL)
ALTER TABLE [dbo].[transaction_log_20050201] ADD PRIMARY KEY
(
[trn_datetime],
[merchant_id],
[id]
)
CREATE TABLE [dbo].[transaction_log_20050301] (
[merchant_id] [int] NOT NULL ,
[id] [int] NOT NULL ,
[trn_datetime] [datetime] NOT NULL CHECK ([trn_datetime] >= cast('3/1/2005'
as datetime)),[trn_value] [varchar] (32) NOT NULL)
ALTER TABLE [dbo].[transaction_log_20050301] ADD PRIMARY KEY
(
[trn_datetime],
[merchant_id],
[id]
)
CREATE VIEW [dbo].[transaction_log]
AS
SELECT * FROM [dbo].[transaction_log_20050101]
UNION ALL
SELECT * FROM [dbo].[transaction_log_20050201]
UNION ALL
SELECT * FROM [dbo].[transaction_log_20050301]

Partitioned View - Errors after bulk inster
SzyKam
Thanks, adding CHECK_CONSTRAINTS solved the problem.
In case this problem occurs for me in a production enviroment and I need to get the optimizer to trust the check constraints again I havn't been able to get this to work. I've reviewed the link your provided and other documentation and I seem to be executing the correct commands but I am still getting the 'partitioning column was not found' error.
I'm using the following commands to update the trust on the check constraints. Can you see anything wrong here
ALTER TABLE [dbo].[transaction_log_20050101] WITH CHECK
ADD CHECK ([trn_datetime] < convert(datetime,'2/1/2005'))
GO
ALTER TABLE [dbo].[transaction_log_20050201] WITH CHECK
ADD CHECK ([trn_datetime] >= convert(datetime,'2/1/2005') and [trn_datetime] < convert(datetime,'3/1/2005'))
GO
ALTER TABLE [dbo].[transaction_log_20050301] WITH CHECK
ADD CHECK ([trn_datetime] >= convert(datetime,'3/1/2005'))
GO
yipsi
BenK_123
Bob1945
Some additional info. I'm using SQL Server 2000 version 8.00.818 SP3 Enterprise Edition.
The full SQL to create the tables and generate the error are the following. The last INSERT command will fail with the message 'UNION ALL view 'transaction_log' is not updatable because a partitioning column was not found.':
CREATE TABLE [dbo].[transaction_log_20050101] (
[merchant_id] [int] NOT NULL ,
[id] [int] NOT NULL ,
[trn_datetime] [datetime] NOT NULL CHECK ([trn_datetime] < cast('2/1/2005'
as datetime)),
[trn_value] [varchar] (32) NOT NULL)
ALTER TABLE [dbo].[transaction_log_20050101] ADD PRIMARY KEY
(
[trn_datetime],
[merchant_id],
[id]
)
CREATE TABLE [dbo].[transaction_log_20050201] (
[merchant_id] [int] NOT NULL ,
[id] [int] NOT NULL ,
[trn_datetime] [datetime] NOT NULL CHECK ([trn_datetime] >= cast('2/1/2005'
as datetime) AND [trn_datetime] < cast('3/1/2005' as datetime)),
[trn_value] [varchar] (32) NOT NULL)
ALTER TABLE [dbo].[transaction_log_20050201] ADD PRIMARY KEY
(
[trn_datetime],
[merchant_id],
[id]
)
CREATE TABLE [dbo].[transaction_log_20050301] (
[merchant_id] [int] NOT NULL ,
[id] [int] NOT NULL ,
[trn_datetime] [datetime] NOT NULL CHECK ([trn_datetime] >= cast('3/1/2005'
as datetime)),[trn_value] [varchar] (32) NOT NULL)
ALTER TABLE [dbo].[transaction_log_20050301] ADD PRIMARY KEY
(
[trn_datetime],
[merchant_id],
[id]
)
--DROP VIEW transaction_log
CREATE VIEW [dbo].[transaction_log]
AS
SELECT * FROM [dbo].[transaction_log_20050101]
UNION ALL
SELECT * FROM [dbo].[transaction_log_20050201]
UNION ALL
SELECT * FROM [dbo].[transaction_log_20050301]
INSERT INTO transaction_log VALUES (1,1,'1/1/2005','Value1')
BULK INSERT NetCmsWeb..transaction_log_20050101
FROM 'C:\temp\transactions.txt'
WITH
(
CODEPAGE = 'ACP',
FIELDTERMINATOR = '\t',
ROWTERMINATOR = '\n'
)
INSERT INTO transaction_log VALUES (4,1,'1/4/2005','Value4')
The contents of c:\temp\transactions.txt are:
2 1 1/2/2005 Value2
3 1 1/3/2005 Value3
Any suggestions would be greatly apreciated, thanks!
mantu_78
I've found the fix to that. I need to drop the check constraints then re-create them. Seems to work that way. Thanks for the help!