No matching unique or primary key for this column-list --error

CREATE TABLE CUSTOMER(CUS_NUM NUMBER(10) PRIMARY KEY,CUS_NAME VARCHAR2(50),ADDRESS VARCHAR2(50));
CREATE TABLE ITEM(ITEM_NUM NUMBER(10),ITEM_DESC VARCHAR2(50),TYPE VARCHAR2(50),ITEM_STATUS VARCHAR2(50),
CONSTRAINT PK_ITEM PRIMARY KEY(ITEM_NUM,TYPE));
CREATE TABLE ITEM_TYPE(TYPE VARCHAR2(50) PRIMARY KEY,TYPE_NAME VARCHAR2(50),SKU VARCHAR2(50),RATING VARCHAR2(50));
CREATE TABLE ORDERS(ORDER_NUMBER NUMBER(10),CUS_NUM NUMBER(10),ITEM_NUM NUMBER(10),ORDER_POINT VARCHAR2(50),DISPATCH_POINT VARCHAR2(50),
PRIORITY VARCHAR2(50),ORDER_STATUS VARCHAR2(50),
CONSTRAINT PK_ORDERS PRIMARY KEY(ORDER_NUMBER,ITEM_NUM),
CONSTRAINT FK1_ORDERS FOREIGN KEY (CUS_NUM) REFERENCES CUSTOMER(CUS_NUM),
CONSTRAINT FK2_ORDERS FOREIGN KEY (ITEM_NUM) REFERENCES ITEM(ITEM_NUM));
Hi,friends i created tables as above when i creating 'ORDERS' table the error will fir as "ORA-02270: no matching unique or primary key for this column-list".
can any body solve this issue.
Cheers,
Sudhir reddy.

For your own sanity, you should learn to format your code, or use a tool to do it for you. For the sanity of the forum members, you should preserve that code using the \ tagsCREATE TABLE CUSTOMER
CUS_NUM NUMBER(10) PRIMARY KEY,
CUS_NAME VARCHAR2(50),
ADDRESS VARCHAR2(50)
CREATE TABLE ITEM
ITEM_NUM NUMBER(10),
ITEM_DESC VARCHAR2(50),
TYPE VARCHAR2(50),
TYPE is a reserved word.  Call it ITEM_TYPEITEM_STATUS VARCHAR2(50),
CONSTRAINT PK_ITEM PRIMARY KEY(ITEM_NUM,TYPE)
CREATE TABLE ITEM_TYPE
TYPE VARCHAR2(50) PRIMARY KEY,
again, with the reserved word.TYPE_NAME VARCHAR2(50),
SKU VARCHAR2(50),
RATING VARCHAR2(50)
CREATE TABLE ORDERS
ORDER_NUMBER NUMBER(10),
be consistent.  NUM or NUMBER.  Pick one and stick with it.CUS_NUM NUMBER(10),
ITEM_NUM NUMBER(10),
ORDER_POINT VARCHAR2(50),
DISPATCH_POINT VARCHAR2(50),
PRIORITY VARCHAR2(50),
ORDER_STATUS VARCHAR2(50),
CONSTRAINT PK_ORDERS PRIMARY KEY(ORDER_NUMBER,ITEM_NUM),
CONSTRAINT FK1_ORDERS FOREIGN KEY (CUS_NUM) REFERENCES CUSTOMER(CUS_NUM),
CONSTRAINT FK2_ORDERS FOREIGN KEY (ITEM_NUM) REFERENCES ITEM(ITEM_NUM)

Similar Messages

  • Primary key for an column consisting duplicates

    hi,
    ------->i have created a table and
    -------> i have a column consisting of 1000 records (but where i have duplicates)
    and now i want to create a primary key for the column
    how can i do it....

    Hi,
    You can find records which contains duplicate values for the table column using Oracle exceptions table. Please see a small demonstration:-
    SQL> create table test1(id number);
    Table created.
    SQL> insert into test1 values(&id);
    Enter value for id: 1
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(1)
    1 row created.
    SQL> /
    Enter value for id: 2
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(2)
    1 row created.
    SQL> /
    Enter value for id: 3
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(3)
    1 row created.
    SQL> /
    Enter value for id: 1
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(1)
    1 row created.
    SQL> /
    Enter value for id: 3
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(3)
    1 row created.
    SQL> /
    Enter value for id: 4
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(4)
    1 row created.
    SQL> /
    Enter value for id: 5
    old 1: insert into test1 values(&id)
    new 1: insert into test1 values(5)
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> alter table test1 add constraint id_pk primary key(id);
    alter table test1 add constraint id_pk primary key(id)
    ERROR at line 1:
    ORA-02437: cannot validate (SYS.ID_PK) - primary key violated
    SQL> alter table test1 add constraint id_pk primary key(id) exceptions into exceptions;
    alter table test1 add constraint id_pk primary key(id) exceptions into exceptions
    ERROR at line 1:
    ORA-02445: Exceptions table not found
    SQL> @?/rdbms/admin/utlexcpt
    Table created.
    SQL> alter table test1 add constraint id_pk primary key(id) exceptions into exceptions;
    alter table test1 add constraint id_pk primary key(id) exceptions into exceptions
    ERROR at line 1:
    ORA-02437: cannot validate (SYS.ID_PK) - primary key violated
    SQL> desc exceptions
    Name Null? Type
    ROW_ID ROWID
    OWNER VARCHAR2(30)
    TABLE_NAME VARCHAR2(30)
    CONSTRAINT VARCHAR2(30)
    SQL> select * from exceptions;
    ROW_ID OWNER TABLE_NAME CONSTRAINT
    AAAc95AABAAA9EpAAD SYS TEST1 ID_PK
    AAAc95AABAAA9EpAAA SYS TEST1 ID_PK
    AAAc95AABAAA9EpAAE SYS TEST1 ID_PK
    AAAc95AABAAA9EpAAC SYS TEST1 ID_PK
    SQL> select * from test1 where rowid in(select row_id from exceptions);
    ID
    3
    1
    1
    3
    Thanks
    Edited by: rarain on May 28, 2013 12:10 PM

  • How to set primary key for a date column

    hello experts .,
    i need to set primary key for a column consists of the datatype date. how to solve this..?

    1008318 wrote:
    its my personal need..then it is a very bad personal need. DATE is not an appropriate type to be using for a primary key, as it cannot be guaranteed to be unique, especially when inserting multiple rows at once.
    You would be better working to business needs and implementing correct technical solutions to those needs, than to just do things based on your personal needs.

  • Primary Key for DSO (2LIS_11_VAKON)

    Dear all:
    I have to create a Standard DSO out of 2LIS_11_VAKON Datasource. My question is how do I define the Primary Key for this DSO...
    I mean: (Doc.Number + Pos.Number) is enough?. or do I need some extra(s) field(s) in the Primary Key?
    Regards.

    Hi
    I have to create a Standard DSO out of 2LIS_11_VAKON Datasource. My question is how do I define the Primary Key for this DSO...
    I mean: (Doc.Number + Pos.Number) is enough?. or do I need some extra(s) field(s) in the Primary Key?
    You can Install the Standard content You cannot Create any Standard DSO.
    You can Create a customized DSO . Though the DSO is a Table There is no need of Primery Key Function here. Hope You are Talking about Data Fields and Key Fields.
    But there is a Standard DSO FOR  0SD_O05 Order: Condition Data.. you can install the same.
    Both fields are needed to report analytical data  based on your criteria.
    http://help.sap.com/saphelp_nw70/helpdata/EN/3c/7b88408bc0bb4de10000000a1550b0/frameset.htm

  • Is it possible to create many primary key for a table?

    hello sir/mam.
    i am selva, i am new to abap,
    is it possible to create many primary key for a table?
    please guide me.

    Hi Selva,
    Many Primary Keys = Composite Key.
    i.e some set of columns will enable you to identify a unique row from a set of rows in the table.
    This can be achieved by checking the primary key check box in se11.
    Hope it helps.
    Regards,
    Maheswaran.B
    Message was edited by: Maheswaran B

  • The column in the table do not match an existing primary key

    I've got two tables tbl_Workshop and tbl_Material
    tbl_Workshop has columns workshopID, workshopTitle, materialID
    tbl_Material has materialID, name, workshopTitle
    when I'm trying to create a relationship between the workshopTitle of tbl1 and tbl2, it gives me an error that says the column in the table do not match an existing primary key.
    What could be the reason for this error and how to overcome it.
    ps. The datatypes and names of both the table's column match.

    Have you created primary key on workshopTitle column in tbl_Workshop
    You can add foreign key relationship from tbl_Material.workshopTitle
    to tbl_Workshop.workshopTitle
     only if latter is a primary key of the table.
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Unique or primary key on timestamp with timezone

    Hi,
    I have been experimenting with a date column in a primary key, or actually I tried using a timestamp with time zone in a primary key.
    While researching whether there was a way to avoid ORA-02329, I found the following:
    K15> create table dumdum
      2    (datum date not null
      3    ,naamp varchar2( 30 ) not null);
    Table created.
    K15>
    K15> alter table dumdum
      2    add constraint d_pk
      3        primary key
      4          (datum, naamp)
      5    using index;
    Table altered.
    K15>
    K15> select ind.index_type
      2  from   user_indexes ind
      3  where  ind.index_name = 'D_PK';
    INDEX_TYPE
    NORMAL
    1 row selected.
    K15>
    K15> insert into dumdum
      2    (datum
      3    ,naamp )
      4  select sysdate - (level/1440)
      5  ,      'nomen nescio'
      6  from   dual
      7  connect by level < 1000
      8  ;
    999 rows created.
    K15>
    K15> analyze index d_pk validate structure;
    Index analyzed.
    K15> analyze table dumdum compute statistics;
    Table analyzed.
    K15>
    K15> select naamp
      2  from   dumdum
      3  where  datum > to_date('16-06-2011 15.46.16', 'dd-mm-yyyy hh24.mi.ss' )
      4 
    K15> For the last select statement I get the following "explain plan":
    SELECT STATEMENT  CHOOSE
              Cost: 2  Bytes: 247  Cardinality: 13       
         1 INDEX RANGE SCAN UNIQUE D_PK
                    Cost: 3  Bytes: 247  Cardinality: 13  This behavior lived up to my expectations.
    Then, I tried this:
    K15> create table dumdum
      2    (datum date not null
      3    ,naamp varchar2( 30 ) not null);
    Table created.
    K15>
    K15> alter table dumdum
      2    add constraint d_pk
      3        primary key
      4          (datum, naamp)
      5    using index;
    Table altered.
    K15>
    K15> alter table dumdum
      2        modify datum timestamp(6) with time zone;
    Table altered.
    K15>
    K15> select ind.index_type
      2  from   user_indexes ind
      3  where  ind.index_name = 'D_PK';
    INDEX_TYPE
    NORMAL
    1 row selected.
    K15>
    K15> insert into dumdum
      2    (datum
      3    ,naamp )
      4  select sysdate - (level/1440)
      5  ,      'nomen nescio'
      6  from   dual
      7  connect by level < 1000
      8  ;
    999 rows created.
    K15>
    K15> analyze index d_pk validate structure;
    Index analyzed.
    K15> analyze table dumdum compute statistics;
    Table analyzed.
    K15>
    K15> select naamp
      2  from   dumdum
      3  where  datum > to_date('16-06-2011 15.46.16', 'dd-mm-yyyy hh24.mi.ss' )
      4
    K15> So, at first glance, the alter table statement to change the datatype from DATE to TIMESTAMP seems like a way of fooling Oracle. But the explain plan reveals a different story:
    SELECT STATEMENT  CHOOSE
              Cost: 4  Bytes: 1,25  Cardinality: 50       
         1 TABLE ACCESS FULL DUMDUM
                    Cost: 4  Bytes: 1,25  Cardinality: 50  I was only fooling myself. :-0
    But I wasn't done with my research:
    K15> create table dumdum
      2    (datum timestamp(6) with time zone not null
      3    ,naamp varchar2( 30 ) not null);
    Table created.
    K15>
    K15> create unique index d_ind
      2      on dumdum
      3           (datum, naamp);
    Index created.
    K15>
    K15>
    K15> select ind.index_type
      2  from   user_indexes ind
      3  where  ind.index_name = 'D_IND';
    INDEX_TYPE
    FUNCTION-BASED NORMAL
    1 row selected.
    K15>
    K15> insert into dumdum
      2    (datum
      3    ,naamp )
      4  select systimestamp - (level/1440)
      5  ,      'nomen nescio'
      6  from   dual
      7  connect by level < 1000
      8  ;
    999 rows created.
    K15>
    K15> analyze index d_ind validate structure;
    Index analyzed.
    K15> analyze table dumdum compute statistics;
    Table analyzed.
    K15>
    K15> select naamp
      2  from   dumdum
      3  where  datum > to_date('16-06-2011 15.56.16', 'dd-mm-yyyy hh24.mi.ss' )
      4
    K15>Now, my explain plan looks fine:
    SELECT STATEMENT  CHOOSE
              Cost: 2  Bytes: 1,25  Cardinality: 50       
         1 INDEX RANGE SCAN UNIQUE D_IND
              Cost: 3  Bytes: 1,25  Cardinality: 50  Why is Oracle so adamant about not allowing a timestamp with time zone in a unique key? And, given their position on the matter, where does their tolerance for a unique index come from?
    By the way, if I had a say in it, I would not allow anything that even remotely looks like a date to be part of a primary key, but that's another discussion.
    Thanks,
    Remco
    P.S. All this is on Oracle9i Enterprise Edition Release 9.2.0.8.0. Is it different on 10g or 11g?

    See if this helps. You can create primary key for TIMESTAMP WITH LOCAL TIME ZONE datatype.
    SQL>CREATE TABLE Mytimezone(Localtimezone TIMESTAMP WITH LOCAL TIME ZONE primary key, Location varchar2(20) );
    Table created.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch4datetime.htm#i1006169
    TIMESTAMP WITH LOCAL TIME ZONE Datatype
    TIMESTAMP WITH LOCAL TIME ZONE is another variant of TIMESTAMP. It differs from TIMESTAMP WITH TIME ZONE as follows: data stored in the database is normalized to the database time zone, and the time zone offset is not stored as part of the column data. When users retrieve the data, Oracle returns it in the users' local session time zone. The time zone offset is the difference (in hours and minutes) between local time and UTC (Coordinated Universal Time, formerly Greenwich Mean Time).
    Thanks
    http://swervedba.wordpress.com/

  • Setting a Primary Key for a newly added Column

    Is it possible for setting a primary key for a newly added column in a table having records?

    Hi,
    km**** wrote:
    oh if the table has records then it is not possible ah...No, the table can have rows at the time you add the Primary Key constraint. Solomon was just saying that the column(s) that you are making into the Primary Key must already have unique values. A Primary Key can not be NULL, so you must do the steps in this order:
    (1) ALTER TABLE to add the column(s) (if this hasn't been done already)
    (2) UPDATE the table, to put unique values in all rows for the Primary Key column(s)
    (3) Add the PRIMARY KEY constraint
    You need to do step (2) before you do step (3)

  • How to genarate Primary Key for each record in XI  Mapping

    Hi,
    I need to genarate primary key for each record in the paylod in mapping..
    Eg: if i have a 10 reacords i need to have a primary key for each record..starting with the
    Record      Primary key
    First            001
    Secound      002
    Tenth         010
    If i need to write any user defined funtion... can any one provide the code for it.
    Thanks
    Amaresh

    Hi Bavesh,
    I will explain with the example:
    XML:
    <Record 1>
    <Primary key>
    <value1>
    <value2>
    </Record 1>
    <Record 2>
    <Primary Key>
    </Record 2>
    like above i will be getting n number of recored and in each record i need  to genarate primary key in XI.and the key sould be in sequence...
    like for the first record 1 secound 2 like that primary key should add to the privous Primary key.
    and this is for each payload.
    Thanks
    Amaresh

  • Primary Key for a view?

    Hi everybody,
    I am wondering if there is such thing as primary key for a view? Assuming, that my view is based on a single table and it's just a subset of columns (some of them renamed) including PK of the table it's based on.
    The reason for my question is this - we're using Reverse POCO generator which automatically generates C# Model class and Configuration file for our tables and views. For the view is lists all the columns as a key and therefore I obviously can not use normal
    way of updating that view. I posted that as an issue here https://efreversepoco.codeplex.com/workitem/115 but I am thinking there is no such thing as the "primary key" for a view.
    The query used to generate the classes is extremely complex already but may be it can be modified to get the PK ?
    SELECT [Extent1].[SchemaName],
    [Extent1].[Name] AS TableName,
    [Extent1].[TABLE_TYPE] AS TableType,
    [UnionAll1].[Ordinal],
    [UnionAll1].[Name] AS ColumnName,
    [UnionAll1].[IsNullable],
    [UnionAll1].[TypeName],
    ISNULL([UnionAll1].[MaxLength],0) AS MaxLength,
    ISNULL([UnionAll1].[Precision], 0) AS Precision,
    ISNULL([UnionAll1].[Default], '') AS [Default],
    ISNULL([UnionAll1].[DateTimePrecision], '') AS [DateTimePrecision],
    ISNULL([UnionAll1].[Scale], 0) AS Scale,
    [UnionAll1].[IsIdentity],
    [UnionAll1].[IsStoreGenerated],
    CASE WHEN ([Project5].[C2] IS NULL) THEN CAST(0 AS BIT)
    ELSE [Project5].[C2]
    END AS PrimaryKey
    FROM (
    SELECT QUOTENAME(TABLE_SCHEMA) + QUOTENAME(TABLE_NAME) [Id],
    TABLE_SCHEMA [SchemaName],
    TABLE_NAME [Name],
    TABLE_TYPE
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE IN ('BASE TABLE', 'VIEW')
    ) AS [Extent1]
    INNER JOIN (
    SELECT [Extent2].[Id] AS [Id],
    [Extent2].[Name] AS [Name],
    [Extent2].[Ordinal] AS [Ordinal],
    [Extent2].[IsNullable] AS [IsNullable],
    [Extent2].[TypeName] AS [TypeName],
    [Extent2].[MaxLength] AS [MaxLength],
    [Extent2].[Precision] AS [Precision],
    [Extent2].[Default],
    [Extent2].[DateTimePrecision] AS [DateTimePrecision],
    [Extent2].[Scale] AS [Scale],
    [Extent2].[IsIdentity] AS [IsIdentity],
    [Extent2].[IsStoreGenerated] AS [IsStoreGenerated],
    0 AS [C1],
    [Extent2].[ParentId] AS [ParentId]
    FROM (
    SELECT QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) + QUOTENAME(c.COLUMN_NAME) [Id],
    QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) [ParentId],
    c.COLUMN_NAME [Name],
    c.ORDINAL_POSITION [Ordinal],
    CAST(CASE c.IS_NULLABLE
    WHEN 'YES' THEN 1
    WHEN 'NO' THEN 0
    ELSE 0
    END AS BIT) [IsNullable],
    CASE WHEN c.DATA_TYPE IN ('varchar', 'nvarchar', 'varbinary')
    AND c.CHARACTER_MAXIMUM_LENGTH = -1 THEN c.DATA_TYPE + '(max)'
    ELSE c.DATA_TYPE
    END AS [TypeName],
    c.CHARACTER_MAXIMUM_LENGTH [MaxLength],
    CAST(c.NUMERIC_PRECISION AS INTEGER) [Precision],
    CAST(c.DATETIME_PRECISION AS INTEGER) [DateTimePrecision],
    CAST(c.NUMERIC_SCALE AS INTEGER) [Scale],
    c.COLLATION_CATALOG [CollationCatalog],
    c.COLLATION_SCHEMA [CollationSchema],
    c.COLLATION_NAME [CollationName],
    c.CHARACTER_SET_CATALOG [CharacterSetCatalog],
    c.CHARACTER_SET_SCHEMA [CharacterSetSchema],
    c.CHARACTER_SET_NAME [CharacterSetName],
    CAST(0 AS BIT) AS [IsMultiSet],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)), c.COLUMN_NAME, 'IsIdentity') AS BIT) AS [IsIdentity],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)), c.COLUMN_NAME, 'IsComputed')
    | CASE WHEN c.DATA_TYPE = 'timestamp' THEN 1
    ELSE 0
    END AS BIT) AS [IsStoreGenerated],
    c.COLUMN_DEFAULT AS [Default]
    FROM INFORMATION_SCHEMA.COLUMNS c
    INNER JOIN INFORMATION_SCHEMA.TABLES t
    ON c.TABLE_CATALOG = t.TABLE_CATALOG
    AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
    AND c.TABLE_NAME = t.TABLE_NAME
    AND t.TABLE_TYPE IN ('BASE TABLE', 'VIEW')
    ) AS [Extent2]
    UNION ALL
    SELECT [Extent3].[Id] AS [Id],
    [Extent3].[Name] AS [Name],
    [Extent3].[Ordinal] AS [Ordinal],
    [Extent3].[IsNullable] AS [IsNullable],
    [Extent3].[TypeName] AS [TypeName],
    [Extent3].[MaxLength] AS [MaxLength],
    [Extent3].[Precision] AS [Precision],
    [Extent3].[Default],
    [Extent3].[DateTimePrecision] AS [DateTimePrecision],
    [Extent3].[Scale] AS [Scale],
    [Extent3].[IsIdentity] AS [IsIdentity],
    [Extent3].[IsStoreGenerated] AS [IsStoreGenerated],
    6 AS [C1],
    [Extent3].[ParentId] AS [ParentId]
    FROM (
    SELECT QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) + QUOTENAME(c.COLUMN_NAME) [Id],
    QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) [ParentId],
    c.COLUMN_NAME [Name],
    c.ORDINAL_POSITION [Ordinal],
    CAST(CASE c.IS_NULLABLE
    WHEN 'YES' THEN 1
    WHEN 'NO' THEN 0
    ELSE 0
    END AS BIT) [IsNullable],
    CASE WHEN c.DATA_TYPE IN ('varchar', 'nvarchar', 'varbinary')
    AND c.CHARACTER_MAXIMUM_LENGTH = -1 THEN c.DATA_TYPE + '(max)'
    ELSE c.DATA_TYPE
    END AS [TypeName],
    c.CHARACTER_MAXIMUM_LENGTH [MaxLength],
    CAST(c.NUMERIC_PRECISION AS INTEGER) [Precision],
    CAST(c.DATETIME_PRECISION AS INTEGER) AS [DateTimePrecision],
    CAST(c.NUMERIC_SCALE AS INTEGER) [Scale],
    c.COLLATION_CATALOG [CollationCatalog],
    c.COLLATION_SCHEMA [CollationSchema],
    c.COLLATION_NAME [CollationName],
    c.CHARACTER_SET_CATALOG [CharacterSetCatalog],
    c.CHARACTER_SET_SCHEMA [CharacterSetSchema],
    c.CHARACTER_SET_NAME [CharacterSetName],
    CAST(0 AS BIT) AS [IsMultiSet],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)), c.COLUMN_NAME, 'IsIdentity') AS BIT) AS [IsIdentity],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)), c.COLUMN_NAME, 'IsComputed')
    | CASE WHEN c.DATA_TYPE = 'timestamp' THEN 1
    ELSE 0
    END AS BIT) AS [IsStoreGenerated],
    c.COLUMN_DEFAULT [Default]
    FROM INFORMATION_SCHEMA.COLUMNS c
    INNER JOIN INFORMATION_SCHEMA.VIEWS v
    ON c.TABLE_CATALOG = v.TABLE_CATALOG
    AND c.TABLE_SCHEMA = v.TABLE_SCHEMA
    AND c.TABLE_NAME = v.TABLE_NAME
    WHERE NOT (
    v.TABLE_SCHEMA = 'dbo'
    AND v.TABLE_NAME IN ('syssegments', 'sysconstraints')
    AND SUBSTRING(CAST(SERVERPROPERTY('productversion') AS VARCHAR(20)), 1, 1) = 8
    ) AS [Extent3]
    ) AS [UnionAll1]
    ON (0 = [UnionAll1].[C1])
    AND ([Extent1].[Id] = [UnionAll1].[ParentId])
    LEFT OUTER JOIN (
    SELECT [UnionAll2].[Id] AS [C1],
    CAST(1 AS BIT) AS [C2]
    FROM (
    SELECT QUOTENAME(tc.CONSTRAINT_SCHEMA) + QUOTENAME(tc.CONSTRAINT_NAME) [Id],
    QUOTENAME(tc.TABLE_SCHEMA) + QUOTENAME(tc.TABLE_NAME) [ParentId],
    tc.CONSTRAINT_NAME [Name],
    tc.CONSTRAINT_TYPE [ConstraintType],
    CAST(CASE tc.IS_DEFERRABLE
    WHEN 'NO' THEN 0
    ELSE 1
    END AS BIT) [IsDeferrable],
    CAST(CASE tc.INITIALLY_DEFERRED
    WHEN 'NO' THEN 0
    ELSE 1
    END AS BIT) [IsInitiallyDeferred]
    FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
    WHERE tc.TABLE_NAME IS NOT NULL
    ) AS [Extent4]
    INNER JOIN (
    SELECT 7 AS [C1],
    [Extent5].[ConstraintId] AS [ConstraintId],
    [Extent6].[Id] AS [Id]
    FROM (
    SELECT QUOTENAME(CONSTRAINT_SCHEMA) + QUOTENAME(CONSTRAINT_NAME) [ConstraintId],
    QUOTENAME(TABLE_SCHEMA) + QUOTENAME(TABLE_NAME) + QUOTENAME(COLUMN_NAME) [ColumnId]
    FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    ) AS [Extent5]
    INNER JOIN (
    SELECT QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) + QUOTENAME(c.COLUMN_NAME) [Id],
    QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) [ParentId],
    c.COLUMN_NAME [Name],
    c.ORDINAL_POSITION [Ordinal],
    CAST(CASE c.IS_NULLABLE
    WHEN 'YES' THEN 1
    WHEN 'NO' THEN 0
    ELSE 0
    END AS BIT) [IsNullable],
    CASE WHEN c.DATA_TYPE IN ('varchar', 'nvarchar', 'varbinary')
    AND c.CHARACTER_MAXIMUM_LENGTH = -1 THEN c.DATA_TYPE + '(max)'
    ELSE c.DATA_TYPE
    END AS [TypeName],
    c.CHARACTER_MAXIMUM_LENGTH [MaxLength],
    CAST(c.NUMERIC_PRECISION AS INTEGER) [Precision],
    CAST(c.DATETIME_PRECISION AS INTEGER) [DateTimePrecision],
    CAST(c.NUMERIC_SCALE AS INTEGER) [Scale],
    c.COLLATION_CATALOG [CollationCatalog],
    c.COLLATION_SCHEMA [CollationSchema],
    c.COLLATION_NAME [CollationName],
    c.CHARACTER_SET_CATALOG [CharacterSetCatalog],
    c.CHARACTER_SET_SCHEMA [CharacterSetSchema],
    c.CHARACTER_SET_NAME [CharacterSetName],
    CAST(0 AS BIT) AS [IsMultiSet],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)),
    c.COLUMN_NAME, 'IsIdentity') AS BIT) AS [IsIdentity],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)),
    c.COLUMN_NAME, 'IsComputed')
    | CASE WHEN c.DATA_TYPE = 'timestamp' THEN 1
    ELSE 0
    END AS BIT) AS [IsStoreGenerated],
    c.COLUMN_DEFAULT AS [Default]
    FROM INFORMATION_SCHEMA.COLUMNS c
    INNER JOIN INFORMATION_SCHEMA.TABLES t
    ON c.TABLE_CATALOG = t.TABLE_CATALOG
    AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
    AND c.TABLE_NAME = t.TABLE_NAME
    AND t.TABLE_TYPE IN ('BASE TABLE', 'VIEW')
    ) AS [Extent6]
    ON [Extent6].[Id] = [Extent5].[ColumnId]
    UNION ALL
    SELECT 11 AS [C1],
    [Extent7].[ConstraintId] AS [ConstraintId],
    [Extent8].[Id] AS [Id]
    FROM (
    SELECT CAST( NULL AS NVARCHAR (1)) [ConstraintId], CAST( NULL AS NVARCHAR (MAX)) [ColumnId] WHERE 1= 2
    ) AS [Extent7]
    INNER JOIN (
    SELECT QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) + QUOTENAME(c.COLUMN_NAME) [Id],
    QUOTENAME(c.TABLE_SCHEMA) + QUOTENAME(c.TABLE_NAME) [ParentId],
    c.COLUMN_NAME [Name],
    c.ORDINAL_POSITION [Ordinal],
    CAST(CASE c.IS_NULLABLE
    WHEN 'YES' THEN 1
    WHEN 'NO' THEN 0
    ELSE 0
    END AS BIT) [IsNullable],
    CASE WHEN c.DATA_TYPE IN ('varchar', 'nvarchar', 'varbinary')
    AND c.CHARACTER_MAXIMUM_LENGTH = -1 THEN c.DATA_TYPE + '(max)'
    ELSE c.DATA_TYPE
    END AS [TypeName],
    c.CHARACTER_MAXIMUM_LENGTH [MaxLength],
    CAST(c.NUMERIC_PRECISION AS INTEGER) [Precision],
    CAST(c.DATETIME_PRECISION AS INTEGER) AS [DateTimePrecision],
    CAST(c.NUMERIC_SCALE AS INTEGER) [Scale],
    c.COLLATION_CATALOG [CollationCatalog],
    c.COLLATION_SCHEMA [CollationSchema],
    c.COLLATION_NAME [CollationName],
    c.CHARACTER_SET_CATALOG [CharacterSetCatalog],
    c.CHARACTER_SET_SCHEMA [CharacterSetSchema],
    c.CHARACTER_SET_NAME [CharacterSetName],
    CAST(0 AS BIT) AS [IsMultiSet],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)),
    c.COLUMN_NAME, 'IsIdentity') AS BIT) AS [IsIdentity],
    CAST(COLUMNPROPERTY(OBJECT_ID(QUOTENAME(c.TABLE_SCHEMA) + '.' + QUOTENAME(c.TABLE_NAME)),
    c.COLUMN_NAME, 'IsComputed')
    | CASE WHEN c.DATA_TYPE = 'timestamp' THEN 1
    ELSE 0
    END AS BIT) AS [IsStoreGenerated],
    c.COLUMN_DEFAULT [Default]
    FROM INFORMATION_SCHEMA.COLUMNS c
    INNER JOIN INFORMATION_SCHEMA.VIEWS v
    ON c.TABLE_CATALOG = v.TABLE_CATALOG
    AND c.TABLE_SCHEMA = v.TABLE_SCHEMA
    AND c.TABLE_NAME = v.TABLE_NAME
    WHERE NOT (
    v.TABLE_SCHEMA = 'dbo'
    AND v.TABLE_NAME IN ('syssegments', 'sysconstraints')
    AND SUBSTRING(CAST(SERVERPROPERTY('productversion') AS VARCHAR(20)), 1, 1) = 8
    ) AS [Extent8]
    ON [Extent8].[Id] = [Extent7].[ColumnId]
    ) AS [UnionAll2]
    ON (7 = [UnionAll2].[C1])
    AND ([Extent4].[Id] = [UnionAll2].[ConstraintId])
    WHERE [Extent4].[ConstraintType] = N'PRIMARY KEY'
    ) AS [Project5]
    ON [UnionAll1].[Id] = [Project5].[C1]
    WHERE NOT ([Extent1].[Name] IN ('EdmMetadata', '__MigrationHistory'));
    Thanks in advance.
    UPDATE. I made a quick Google search and found this
    http://stackoverflow.com/questions/1013333/entity-framework-and-sql-server-view/2715299#2715299
    It sounds as an interesting idea to try although I am not sure it will work with POCO Generator. But I'm going to try it now anyway.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

    UPDATE. Changing my view to be
    USE [SiriusSQL_SysManager]
    GO
    /****** Object: View [dbo].[SiriusV_SalesPointsLicensesList] Script Date: 4/30/2015 1:28:54 PM ******/
    DROP VIEW [dbo].[SiriusV_SalesPointsLicensesList]
    GO
    /****** Object: View [dbo].[SiriusV_SalesPointsLicensesList] Script Date: 4/30/2015 1:28:54 PM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    create view [dbo].[SiriusV_SalesPointsLicensesList]
    as
    select ISNULL(salespoint,'') as Salespoint
    , CAST(loc_suffix as smallint) as Id
    , CAST(descrip as varchar(25)) as [Description]
    , cast(mode as tinyint) as Mode
    , cast(is_access as bit) as AccessWare
    , cast(is_adv_inv as bit) as AdvInventory
    , cast(is_cw_crdt as bit) as CardwareCredit
    , cast(is_debit as bit) as DebitWare
    , cast(is_dir_net as bit) as DirectNet
    , cast(is_fbquick as bit) as FBQuickService
    , cast(is_fbtable as bit) as FBTableService
    , cast(is_grpschd as bit) as ResourceScheduling
    , cast(is_guests as bit) as Guests
    , cast(is_pass as bit) as PassWare
    , cast(is_pms as bit) as PMSInterface
    , cast(is_rental as bit) as RentWare
    , cast(is_dual as bit) as DualBook
    , cast(is_pod as bit) as PodBook
    , cast(is_private as bit) as PrivateBook
    , cast(is_resrv as bit) as Reservations
    , cast(is_teesht as bit) as TeeSheet
    , cast(is_rungk as bit) as RunGKInSales
    , cast(is_resseat as bit) as ReservedSeating
    , cast(is_kcashls as bit) as KioskCashless
    , cast(is_ksales as bit) as KioskSales
    , cast(is_kwilcal as bit) as KioskWillCall
    , cast(is_payplan as bit) as PaymentPlan
    , cast(is_test as bit) as Test
    from dbo.sales_pt
    where hidden = 0 ;
    GO
    worked!!! I now have just salespoint as the Key.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Database Copy can't copy primary key for tables

    When I use Tools->Database Copy Wizard to copy my existing schema (for example: azteca_KSMMS) to a brand new schema (azteca), I find the primary key for some of the tables can't be copied, also the views seem not valid under the new schema (azteca). Please give me your comments about that. Thanks for your help.
    Kevin

    For example I have a table called workorder, it has a primary key with name (CW_PKEY_519, on WORKORDERID column) from the source schema (azteca_KSMMS). After I database copy to new schema azteca, the primary key lost. The data of workorder and other indexes have been copied to azteca schema.
    Kevin

  • Primary Key for Programmatic View

    Hi,
    I am using Jdev R2 for ADF. When I create a programmatic VO, Is it necessary to have a primary key for Programmatic VO, if yes, what can be the effective primary key?
    - Vinoth

    Hi Vino,
    Primary keys are used to loop through the collection on tables, list of values and to access rows on a view object.
    Juan Camilo

  • Primary key for table

    I have a table Gr_order which was populated ages ago and now it need to be populated
    with some more look up data.
    "Orderid" is primary key for the table but question is how do I insert "orderid" in insert statement in procedure. I could not find any sequence name. There are 1230
    records which need to be inserted.
    Desc Gr_order
    Orderid  Number Primary key
    Desc     Varchar2
    INSERT INTO gr_order (orderid,desc) 
    VALUES (???, upper(each_pom.desc);Thanks
    sandy

    You find the code that inserts into the table and see if it uses the sequence ;-) . A sequence is not "attached" to a particular table - it is up to the inserting statement to decide if a sequence is to be used.
    You might want to check if the table has a trigger - some developers like to emulate MS-sql server behaviour by having a trigger on the table that selects from a sequence. If it has such a trigger, then you just do your inserts without specifying order_id. But if the table does not have such a trigger, then you cannot know if the table was originally populated using a sequence or not (unless you can find the insert statements somewhere.)

  • How add new field as primary key for existing table

    Hi,
    There is table with name REVIEWER_REUSE_EFFORT and the table has 8000 rows in it.
    Now the enhacement i must do on this table is there is no primary key on this table. so i must create a ID also add values to this table of ID
    Table structure is like this
    Create table REVIEWER_REUSE_EFFORT
    PRO_ID number,
    POBJ_ID number,
    TASK_ID number,
    POTENTIAL_EFFORT number,
    COMMENTS varchar2(1200),
    CREATED_BY varchar2(100),
    CREATION_DATE sysdate
    UPDATED_BY varchar2(1200),
    UPDATED_DATE sysdate
    Please suggest me how to add values in that 8000 rows
    Thanks
    Sudhir

    Hi,
    If you want to add a new column and update the new column with sequence of number
    alter table REVIEWER_REUSE_EFFORT add (ID number);
    update REVIEWER_REUSE_EFFORT  set ID=rownum;Regards,
    Prazy
    Edited by: Prazy on Jun 21, 2010 3:13 PM

  • Table creation from type - Primary key with 2 columns

    Hello,
    I have to create a table from a type that I created.
    The thing is that I want to create a primary key using two column.
    Because this table is junction table.
    How can I do this ?
    CREATE TABLE CONTENT OF CONTENT_T (ID_COMP primary key, ID_CHAR_J NOT NULL PRIMAR
    Y KEY);
    Oracle return:
    CREATE TABLE CONTENT OF CONTENT_T (ID_COMP primary key,ID_CHAR_J NOT NULL PRIMARY KEY)
    ERROR at line 1:
    ORA-02260: table can have only one primary key
    So I tried:
    CREATE TABLE CONTENT OF CONTENT_T (ID_COMP,ID_CHAR_J NOT NULL PRIMARY KEY)
    ERROR at line 1:
    ORA-02338: missing or invalid column constraint specification
    Tahnk's in advance.
    Edited by: user8266437 on 29 avr. 2009 13:56
    Edited by: user8266437 on 29 avr. 2009 13:56

    SCOTT@orcl_11g> CREATE OR REPLACE TYPE content_t AS OBJECT
      2    (id_comp    NUMBER,
      3       id_char_j  VARCHAR2 (10),
      4       other_cols VARCHAR2 (10));
      5  /
    Type created.
    SCOTT@orcl_11g> CREATE TABLE CONTENT OF CONTENT_T (PRIMARY KEY (ID_COMP, ID_CHAR_J))
      2  /
    Table created.
    SCOTT@orcl_11g> INSERT INTO content VALUES (content_t (1, 'A', 'WHATEVER'))
      2  /
    1 row created.
    SCOTT@orcl_11g> COMMIT
      2  /
    Commit complete.
    SCOTT@orcl_11g> INSERT INTO content VALUES (content_t (1, 'A', 'DUPLICATE'))
      2  /
    INSERT INTO content VALUES (content_t (1, 'A', 'DUPLICATE'))
    ERROR at line 1:
    ORA-00001: unique constraint (SCOTT.SYS_C0062057) violated
    SCOTT@orcl_11g> COMMIT
      2  /
    Commit complete.
    SCOTT@orcl_11g> SELECT * FROM content
      2  /
       ID_COMP ID_CHAR_J  OTHER_COLS
             1 A          WHATEVER
    SCOTT@orcl_11g>

Maybe you are looking for