UNION ALL 视图 'tb' 不可更新,因为没有找到分区列
create table tb1
(
YearChar varchar(4) check(YearChar= '2003 '),
NewsChar varchar(1000),
FID varchar(10),
primary key(FID)
)
create table tb2
(
YearChar varchar(4) check(YearChar= '2004 '),
NewsChar varchar(1000),
FID varchar(10),
primary key(FID)
)
create table tb3
(
YearChar varchar(4) check(YearChar= '2005 '),
NewsChar varchar(1000),
FID varchar(10),
primary key(FID)
)
create view tb
as
select * from tb1
union all
select * from tb2
union all
select * from tb3
insert into tb values( '2003 ', '2003武汉家居会展 ', '000000001 ')
insert into tb values( '2004 ', '2004武汉家居会展 ', '000000002 ')
insert into tb values( '2005 ', '2005武汉家居会展 ', '000000003 ')
插入数据时提示
服务器: 消息 4436,级别 16,状态 12,行 1
UNION ALL 视图 'tb ' 不可更新,因为没有找到分区列。
------解决方案--------------------确实,用复合关键字即可。
--可以,但要指定分区列的约束范围不重复。
create table tb1
(
YearChar varchar(4) check(YearChar= '2003 '),
NewsChar varchar(1000),
FID varchar(10),
CONSTRAINT [tb1_FID] PRIMARY KEY (YearChar, [FID] ) ON [PRIMARY]
) ON [PRIMARY]
go
create table tb2
(
YearChar varchar(4) check(YearChar= '2004 '),
NewsChar varchar(1000),
FID varchar(10),
CONSTRAINT [tb2_FID] PRIMARY KEY (YearChar, [FID] ) ON [PRIMARY]
) ON [PRIMARY]
go
create table tb3
(
YearChar varchar(4) check(YearChar= '2005 '),
NewsChar varchar(1000),
FID varchar(10),
CONSTRAINT [tb3_FID] PRIMARY KEY (YearChar, [FID] ) ON [PRIMARY]
) ON [PRIMARY]
go
create view tb
as
select * from tb1
union all
select * from tb2
union all
select * from tb3
go
insert into tb values( '2003 ', '2003武汉家居会展 ', '000000001 ')
insert into tb values( '2004 ', '2004武汉家居会展 ', '000000002 ')
insert into tb values( '2005 ', '2005武汉家居会展 ', '000000003 ')
drop table tb1,tb2,tb3
drop view tb