declare @s varchar(1000)
set @s = 'CREATE VIEW dbo.v1 AS (select * from '+@table1+') union all (select * from '+@table2+')'
exec (@s)

解决方案 »

  1.   

    不对啊,我update视图时提示
    UNION ALL 视图 'pm_ifcodeRptC_de_all_V' 不可更新,因为没有找到分区列。
      

  2.   

    select * from (select * from table_200306 union all select * from table_200307) tmp
      

  3.   

    我想要update 分区视图,该怎么做
      

  4.   

    update分区视图该怎么做?
    请高手帮忙
      

  5.   

    例如,正在将一个 Customer 表分区成三个表。这些表的 CHECK 约束为:CREATE TABLE Customer_33
      (CustomerID   INTEGER PRIMARY KEY
                    CHECK (CustomerID BETWEEN 1 AND 32999),
      ... -- Additional column definitions)
    CREATE TABLE Customer_66
      (CustomerID   INTEGER PRIMARY KEY
                    CHECK (CustomerID BETWEEN 33000 AND 65999),
      ... -- Additional column definitions)
    CREATE TABLE Customer_99
      (CustomerID   INTEGER PRIMARY KEY
                    CHECK (CustomerID BETWEEN 66000 AND 99999),
      ... -- Additional column definitions)CREATE VIEW Customers AS
       SELECT * FROM Customers_33
    UNION ALL
       SELECT * FROM Customers_66
    UNION ALL
       SELECT * FROM Customers_99
    -----------------------------------------------------------------
    CustomerID 即为分区列
      

  6.   

    这个我知道的,但能否用我的主键来区分呢?cid和iid
      

  7.   

    另外,你的表table_200306、table_200307设计的有问题,无法设置分区列。
      

  8.   

    好啊,我的数据就是每月一张表,这个约束怎么写呢?
    pubdate between    and
      

  9.   

    6月份的表:pubdate between   '2003-06-01' and '2003-06-30'
    7月份的表:pubdate between   '2003-07-01' and '2003-07-31'
    ...................................................
      

  10.   

    create table table_200306 (cid varchar(10),iid int,cvalue varchar(10),yearmonth int not null default 200306 check(yearmonth=200306),
    constraint pk_table_200306 primary key (cid,yearmonth))
    create table table_200307 (cid varchar(10),iid int,cvalue varchar(10),yearmonth int not null default 200307 check(yearmonth=200307),
    constraint pk_table_200307 primary key (cid,yearmonth))