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

Similar Messages

  • 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)

  • 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.

  • 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)

  • Violation of PRIMARY KEY constraint . Cannot insert duplicate key in object

    hi i am using SQL Server, when i try to insert data from my jsp page it is inserting the data double time and when i try to submit for second time it is showing the following error.
    Violation of PRIMARY KEY constraint 'PK_EMPLOYEE'. Cannot insert duplicate key in object 'EMPLOYEE'.
    I didnt set identity for primary key. If i try to set identity to true then it is allowing data to submit only if i uncheck my primary key column in cached row set. And if i uncheck that primary key element then i can not retrieve the data by edit button. So how to solve this problem.
    Please any help would be appreciated.
    Thank You in Advance.

    Hi,
    I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
    and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
    load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
    try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
    Thank you,
    Bala Murali Krishna Medipally.
    I suspect you are trying to insert modified records instead of updating.

  • 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>

  • 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

  • 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 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

  • 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 With Four Column ,How to use that Column As Primary Key In Form

    Dear All,
    i have create composite Key as primary Key With Four Column .
    How can i use these column in Form With Report Page.
    How can i use these four Column as primary Key to Edit Record .
    How can i do this.
    Thanks
    Vedant

    wrap a view around your table with this bogus primary key. Use an instead of trigger to handle the inserts and updates. And then look at using surrogate keys to resolve these bad design issues...
    5 out of 4 people don't understand fractions.
    Thank you,
    Tony Miller
    Webster, TX

  • SSIS - "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object ' tablename '. The duplicate key value is 1234 . Though there are no duplicate records.

    Hi,
    I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
    and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
    load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
    try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
    Thank you,
    Bala Murali Krishna Medipally.

    Hi,
    I am providing support to one of our clients, where we have jobs scheduled to load the data from the tables in the source database to the destination database via SSIS packages. The first time load is a full load where we truncate all the tables in the destination
    and load them from the source tables. But from the next day, we perform the incremental load from source to destination, i.e., only modified records fetched using changed tracking concept will be loaded to the destination. After full load, if we run the incremental
    load, the job is failing with the error on one of the packages "Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object '<tablename>'. The duplicate key value is <1234>, even though there are no duplicate records. When we
    try debugging and running the failing package, it runs successfully. We are not able to figure out why the package fails and when we run the next day it runs successfully. Request you to help me in this regard.
    Thank you,
    Bala Murali Krishna Medipally.
    I suspect you are trying to insert modified records instead of updating.

  • 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

  • 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.)

Maybe you are looking for

  • Read-only problem with sun one

    hello i have mounted yestarday a file in which i have created an ejb call Client. Today i have unmounted the file with the ejb Client and i have mounted an other file in which i have created an ejb called Client. Now i can't no more manipulate the fi

  • Having problem with correct color using Photoshop Elements 9 and Hp photosmart c6150.

    Have been trying to print pictures from PSE9 to HP Photosmart C6150 and the colors are overly red and not the same as the original photo.  I tried to get the ICC profile online without any success.  How do I setup my color management on PSE9 and my C

  • Where is the performance analyzer in Solaris Studio?

    I have Oracle Solaris Studio 12.2 linux tar version. I have searched for the performance analyzer integrated with the IDE as in this link http://webcast-west.sun.com/interactive/09D02151/index.html that explains how to use openmp-3 on Solaris Studio

  • CS5 Clone stamp is translucent??

    I'm a bit baffled by the behavior of the clone stamp tool (v12.0.4 x64). I've been using Photoshop Mac for a very long time, and have always gotten a 100% opaque result from the clone tool. Now when I try to clone from one area to another, the clone

  • Urgent!! How  to find all applications implemented on portal?

    Hi all, i am implementing a new portal, my requirement is i have my current portal running and have many applications and components implemented on it, i want to reflect all these on my new portal, so is there any method available so that i can searc