Adding 2 primary keys in mdf database in VS Community 2013 from Server Explorer

Hello,
I have to update a Windows Forms application using VS Community 2013. I have to add a little database with customers and installations, so 1 customer can manage many installations and 1 installation can be managed by many customers. It is the first
time that use VS 2013 so I don't know if I have done all steps well:
Right click in the project item -> Add -> New item -> Data -> Service-base Database. I don't know what "service-based" means, but is the only way I can see to add a database. This step added
mydb.mdf file to the project.
Server Explorer -> Data Connections -> mydb.mdf -> Right click on Tables -> Add New Table. I have added
Customer and Installation tables with no problem. These are T-SQL scripts:
CREATE TABLE [dbo].[Customer]
[UserName] NVARCHAR(50) NOT NULL PRIMARY KEY,
[Password] NVARCHAR(50) NOT NULL,
[FullName] NVARCHAR(50) NOT NULL,
[Company] NVARCHAR(50) NULL,
[Contact] NVARCHAR(100) NULL
CREATE TABLE [dbo].[Installation]
[Imei] NVARCHAR(15) NOT NULL PRIMARY KEY,
[Ip] NVARCHAR(15) NOT NULL,
[Name] NVARCHAR(50) NOT NULL
Now, I have to create CustomerInstallation table with 2 primary keys. The script:
CREATE TABLE [dbo].[CustomerInstallation]
[UserName] NVARCHAR(50) NOT NULL ,
[Imei] NVARCHAR(15) NOT NULL,
PRIMARY KEY ([UserName]),
PRIMARY KEY ([Imei]),
CONSTRAINT [FK_CustomerInstallation_Customer] FOREIGN KEY ([UserName]) REFERENCES [Customer]([UserName]),
CONSTRAINT [FK_CustomerInstallation_Installation] FOREIGN KEY ([Imei]) REFERENCES [Installation]([Imei])
When I click the Update button, I get the following error message:
Update cannot proceed due to validation errors.
Please correct the following errors and try again.
SQL71533 :: A table or table-valued function ([dbo].[CustomerInstallation]) contains more than one primary key.
SQL71531 :: The table or view ([dbo].[CustomerInstallation]) has more than one clustered index.
So my question is: How can I add 2 primary keys to the table? Is it posible with this "service-based" database?
Thank you for all,
Jon.
PD: I didn't know in what forum write this question, please, move this thread to the appropriate forum. Sorry for the inconvenience.

You can only have one primary key per table but the primary key can be over multiple columns so:
CREATE TABLE [dbo].[CustomerInstallation]
    [UserName] NVARCHAR(50) NOT NULL , 
    [Imei] NVARCHAR(15) NOT NULL, 
    PRIMARY KEY ([UserName], [Imei]),    
    CONSTRAINT [FK_CustomerInstallation_Customer] FOREIGN KEY ([UserName]) REFERENCES [Customer]([UserName]),
    CONSTRAINT [FK_CustomerInstallation_Installation] FOREIGN KEY ([Imei]) REFERENCES [Installation]([Imei])
will let you have both columns as part of the primary key

Similar Messages

  • EjbCreate() method return primary key genereted by database

    Hello Everyone,
    I have entity CMP EJB that maps MySQL database table, which is set to asign Primary key (integer) to new entries automatically by using AUTO_INCREMENT. The problem is ejbCreate(..) method, which returns primary key. My question is: how to make it return primary key generated by database?
    Thanks

    Hi,
    I'm also facing the same problem also. The problem is: how do I code the ejbCreate method?
    If I don't initialize the primary key field, I get a complaint that the primary key field needs to be initialized in ejbCreate.
    But if I try to initialize it to an arbitrary value, the database won't allow me to do the insert, because the primary key is auto-generated.

  • Determining the primary key in a database table

    Hi people..
    I am building an interface which displays the database information...according to the specified datasource name..
    Up till now i managed to display the different tables and the respective attributes...
    Is there a way of how i can determine (through java code) if an attribute is the primary key or not of the corresponding table??
    Thanks for your time..
    Regards
    S

    Hi thanks for your reply however when i run the above code i get the following exception..
    java.sql.SQLException: [Microsoft][ODBC Driver Manager] Driver does not support this function
    the statement causing such exception is ..
    ResultSet rs = dbMetaData.getPrimaryKeys(null, null, tableName);
    Do you have any suggestions...??? Sincerely i dont know what i can do..If it can helps the database i m connecting to is an access 2000 database and i am connecting to the database like this:
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection connection = DriverManager.getConnection("jdbc:odbc:"+dataSourceName,username,password);
    Thanks a lot again

  • Primary Key - Generated by database TRIGGER

    Hi,
    I have a form with a block that is attached to a table. So far, nothing fancy :-)
    The Primary is generated with an ORACLE SEQUENCE. That is done at the TABLE level with a DATABASE trigger.
    So in the form, the primary field is not populated.
    Works fine. But if the user wants to UPDATE the forms content, right after they did an INITIAL commit, THEY CAN'T !!!!!!!!!!!
    How can I code this in the form?
    Is there a way to syncronize (populate) the primary key in the form with it's table content?
    If so, how do I query the table if I don't have the primary key value ?
    Thanks for ANY advise,
    Marc.

    Another solution is to use both a database trigger and a PRE-INSERT trigger in Forms.
    The database trigger should be something like
    CREATE TRIGGER INS_TABLENAME BEFORE INSERT ON TABLENAME
    FOR EACH ROW WHEN (new.ID IS NULL)
    BEGIN
    SELECT TABLENAME_SEQ.nextval INTO :new.ID FROM DUAL;
    END;
    and the PRE-INSERT trigger should be something like:
    SELECT TABLENAME_SEQ.nextval INTO :blockname.ID FROM DUAL;
    This way one solves the problem of DML RETURNING VALUE not working in Forms with Oracle version > 8 (does it work on version 8 as it is said to be? - i have not tested it anyway) and the use of other applications (SQL*Plus, JAVA, etc) without writing any code.

  • [SOLVED] Show only primary key columns in database diagrams

    Hi,
    I'd like to create a database diagram with some tables hiding all the columns that aren't primary key or foreign key.
    Currently the only way that I've found is right click on the column's name (in the table body visualized into the diagram) --> Hide selected shape
    I've found the option that permits to visualize the constraint name and (optionally) the relative fields on the same row but what I'd like is something like:
    <Table name>
    <column_name> PK
    <column_name> PK
    <column_name> FK1
    <column_name> FK2
    Do you know a way to do this?
    Many thanks
    Best regards
    Message was edited by:
    Tranen

    Hi Tranen,
    you can view the constraints and respective columns by setting the
    Table Shape Properties in the Property Inspector.
    Select (all) the tables on the Diagram you want
    In the Property Inspector,under Constraints -Set the 'Show Constraint Columns' to 'True',
    Set 'Show Constraints' to 'True' .
    Constraints (PK,UK,FK,Check)
    Also Set the 'Show Columns' option to 'False' .This will be under display options in the Property inspector.
    This should modify the Table shape in the diagram as follows:
    <Table name>
    <PK> PKName:Column1,Column2
    <UK>UKName:Column3
    <FK>FKname:Column1
    are you looking for the same?
    Thanks.

  • Adding 2 new fields as Primary Key field in a Z Table which is existing PRD

    Hi Friends,
    I have to add two new fields as primary key fields in a Z TABLE, which is existing in Quality and Production Systems with Data.
    If I incorporate these two new fields (Primary Key fields) in development and if the TR is moved to Quality and Production sytems, is there any possibility of loss in data will happen at Quality and Prd systems?
    At present, Table is having 20 fields with 2 primary key fields and i have to add 2 more primary key fields.
    I have checked in SCN and not find relevant threads.
    Please help me out.
    Regards,
    Suresh.

    NO . It wont be a problem .
    For ex :
    If you have VBELN  , POSNR are key fields now , you have an unique reord with that combination .
    If you add one other field in it  fo ex  VKBUR  then records will be like this
    VBELN     POSNR     VKBUR   MATERIAL   QTY
    10020      10                            abcxyz      1
    10020      10            1234        abcxyz     1
    So your previous records before adding new primary keys , will have new fields balnk , and the new records will have data filled up in all primary key fields .
    However , if you try to update the existing records that will be in existing PRIMARYKEY combination only .
    for example if you try update record 1 above with VKBUR value 85858 , it creates a new record , it wont be updated in existing record.
    Hope this helps , Pls let me know if u have any more doubts.

  • How can I use a mySQL database schema with numeric auto increment primary key instead of GUID?

    Hello!
    I'm using the TestStand "MySQL Insert (NI)" database schema with GUID as primary key. So everything works fine.
    But I prever using numeric values as primary key, because the database is in conjunction with another database which uses numeric values as primary key.
    Is this possible?
    Has anyone an idea how I can modify the "Generic Recordset (NI)" for use with MySQL?
    Thanks!
    Configuration:
    Microsoft Windows XP
    TestStand 3.1
    MySQL 4.1.12a
    MySQL ODBC 3.51 Driver
    Brosig

    Adam -
    The TestStand Database Logging feature does not allow you to run a separate SQL command after executing the command for a statement(table), so I do not think that you can use an auto incrementing column for the tables. There is just no way to get it back in a generic way. One option that I tried is something similar to the Oracle schema where you call a store procedure to return a sequence ID for each record that you want to add.
    So you would have to create the following sequence table in MySQL:
    CREATE TABLE sequence (id INT NOT NULL);
    INSERT INTO sequence VALUES (0);
    Then create a stored procedure as shown below that will increment the sequence value and return it in a recordset:
    CREATE PROCEDURE `getseqid`()
    BEGIN
            UPDATE sequence SET id=LAST_INSERT_ID(id+1);
            SELECT LAST_INSERT_ID();
    END
    Then update the MySQL tables to use INT primary and foreign key values, so the TestStand MySQL SQL file to create all tables would have text like this:
    CREATE TABLE UUT_RESULT
     ID    INT  PRIMARY KEY,
    ~
    CREATE TABLE STEP_RESULT
     ID    INT  PRIMARY KEY,
     UUT_RESULT   INT  NOT NULL,
    ~
    Then update the schema primary and foreign key columns in the TestStand Database Options dialog box to be INT to match the table. For the primary key columns, you will have to set the Primary Key Type to "Get Value from Recordset" and set the Primary Key Command Text to "call getseqid()". This will call the stored procedure to determine the next value to use as the ID value.
    Hope this helps...
    Scott Richardson
    National Instruments

  • Oh.. Primary key index is missing!

    Database: 10.2.0.4.0
    Platform : Linux
    SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME FROM DBA_CONSTRAINTS WHER
    E TABLE_NAME='ISSUE_COMMENTS';
    CONSTRAINT_NAME C STATUS VALIDATED
    SYS_C0031516 C ENABLED VALIDATED
    SYS_C0031517 C ENABLED VALIDATED
    SYS_C0031519 P ENABLED VALIDATED
    SQL> SELECT INDEX_NAME,TABLE_NAME FROM DBA_INDEXES WHERE TABLE_NAME='ISSUE_COMMENTS';
    INDEX_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS ISSUE_COMMENTS
    SQL> select distinct index_name,column_name,table_name from dba_ind_columns wher
    e table_name in ('ISSUE_COMMENTS');
    INDEX_NAME COLUMN_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS IDX ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS ISSUE_ID ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS PARENT_ID ISSUE_COMMENTS
    Where is the index for the primary key 'SYS_C0031519'?
    SQL>
    After droping and recreating the primary key also,just primary constrainy is created but there is no corresponding index.
    SQL> ALTER TABLE ISSUE_COMMENTS DROP CONSTRAINT SYS_C0031519;
    Table altered.
    SQL> ALTER TABLE ISSUE_COMMENTS ADD PRIMARY KEY (IDX)
    2 USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
    3 STORAGE(INITIAL 32768 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
    4 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
    5 TABLESPACE "TABLE_DATA" ENABLE;
    Table altered.
    SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,status,validated FROM DBA_CONSTRAINT
    S WHERE TABLE_NAME='ISSUE_COMMENTS';
    CONSTRAINT_NAME C STATUS VALIDATED
    SYS_C0031516 C ENABLED VALIDATED
    SYS_C0031517 C ENABLED VALIDATED
    SYS_C0034310 P ENABLED VALIDATED
    SQL> SELECT INDEX_NAME,TABLE_NAME FROM DBA_INDEXES WHERE TABLE_NAME='ISSUE_COMMENTS';
    INDEX_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS ISSUE_COMMENTS
    SQL> select distinct index_name,column_name,table_name from dba_ind_columns wher
    e table_name in ('ISSUE_COMMENTS');
    INDEX_NAME COLUMN_NAME TABLE_NAME
    INDEX_ISSUE_COMMENTS IDX ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS ISSUE_ID ISSUE_COMMENTS
    INDEX_ISSUE_COMMENTS PARENT_ID ISSUE_COMMENTS
    Here also, the primary key constraint SYS_C0034310 is available but there is no index for that primary key.
    Where the primary index has gone?

    MohanaKrishnan wrote:
    Database: 10.2.0.4.0
    Platform : Linux
    SQL> SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE,INDEX_NAME FROM DBA_CONSTRAINTS WHER
    E TABLE_NAME='ISSUE_COMMENTS';
    CONSTRAINT_NAME C STATUS VALIDATED
    SYS_C0031516 C ENABLED VALIDATED
    SYS_C0031517 C ENABLED VALIDATED
    SYS_C0031519 P ENABLED VALIDATED
    Your first query is not consistent with the first set of results you have displayed.
    Your later query for index columns is also not very helpful as it won't list the column names in the right order.
    The probably answer to your question is that the index you have is non-unique and starts with the column you've used for the primary key, which means Oracle can use it to support the primary key constraint. Here's a quick cut-n-paste from a SQL*Plus session to demonstrate the point:
    SQL> create table t1 (n1 number, v1 varchar2(10));
    Table created.
    SQL> create index t1_n1 on t1(n1);
    Index created.
    SQL> alter table t1 add primary key(n1);
    Table altered.
    SQL> select index_name from user_indexes where table_name = 'T1';
    INDEX_NAME
    T1_N1
    1 row selected.
    SQL> select constraint_name, constraint_type, index_name from user_constraints
      2  where table_name = 'T1';
    CONSTRAINT_NAME      C INDEX_NAME
    SYS_C0033465         P T1_N1
    1 row selected.
    SQL> spool offNote how I've added a primary key with no name, and Oracle has decided to use the t1_n1 index to support it.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    http://www.jlcomp.demon.co.uk
    "Science is more than a body of knowledge; it is a way of thinking" Carl Sagan
    Edited by: Jonathan Lewis on Dec 31, 2008 2:16 PM
    Apologies to Satish - I didn't see either prior post

  • Duplicate entries for same primary key

    Hi,
    I am facing problem to insert 2 or more than 2 entries for same PRIMARY KEY in the database table.
    As I know that we can’t do that. But Client has given me the XL sheet which contains 2 entries for same primary key. How can it be done? Please let me know how can I insert 2 data for same primary key in database table.
    Waiting for your answers.
    Thanks in advance.
    Regards,
    Prasanna

    Hi,
      You can achieve this .... All you have to do is to add a new field (a Sequence Number ) to the table. This number will be incremented for each duplicate primary keys. For example....
    Consider the excel file has duplicate entries 3 primary keys. Now you add a new field named Sequence Number in your DB Table.....
    When you load the data into Database...then the records will look like this...
    Key1     Key2    Key3    Seq
    A          B          C           1
    A          B          C           2
    A          B          D           1
    A          B          D           2
    A          C          D           1
    A          C          E           1
      and so on...
    I hope this solves your purpose.....
    Whenever there are duplicate entries, such as the one mentioned in your scenario, then a new field can be added in Database. This field acts like a count or sequence number.... Thus you can maintain unique records.
    Regards,
    Vara
    Regards,
    Vara

  • Diff b/w primary key and unique key?

    what is the diff b/w primary key and unique key?

    Hi,
    With respect to functionality both are same.
    But in ABAP we only have Primary key for the Database tables declared in the Data Dictionary.
    Unique is generally is the term used with declaring key's for internal tables.
    Both primary and Unique keys can identify one record of a table.
    Regards,
    Sesh

  • Case In-Sensitive primary key (NVARCHAR2 datatype) in Oracle 10g

    I have primary keys in my database which are of NVARCHAR2 type. By default data is inserted into these columns as case sensitive which means insertion of both 'ABCD' and 'Abcd' are allowed.
    Can I change the settings in Oracle so that the primary keys work case in-sensitively? I wanted Oracle to throw an error if someone is inserting 'Abcd' and if there is already a record with primary key 'ABCD'.
    Note: I am using Entity Framework.

    Some ideas:
    One method would be to place a before insert trigger on the data and upper it.
    You could add another column, populate via a trigger as upper(), then build a unique index on this column.
    See the following Oracle documentation on case insensitive searchs and comparisons
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch5lingsort.htm#i1008800
    Oracle support documents:
    Develop Global Application: Case-insensitive searches #342960.1
    How to use Contains As Case-Sensitive And -Insensitive On The Same Column #739868.1
    How To Implement Case Insensitive Query in BC4J ? #337163.1
    HTH -- Mark D Powell --

  • Can we create an APEX Form based on Table which has no Primary Key

    Hi,
    I have a requirement.
    I need to create a FORM based on a table having no Primary Key but it is having Unique Key . I can use Unique Key as an alternate of Primary Key.
    but When I tried to create a Form, I got the following message.
    Source tables for forms and tabular forms must have a primary key
    Thanks,
    Deepak

    Deepak_J wrote:
    Hi,
    I have a requirement.
    I need to create a FORM based on a table having no Primary Key but it is having Unique Key . I can use Unique Key as an alternate of Primary Key.
    but When I tried to create a Form, I got the following message.
    Source tables for forms and tabular forms must have a primary key
    Thanks,
    DeepakGood database design will always require a PK on the tables. There are only very few and rare expetions to this rule. One would be when you have store the data only temporarily in this table, like it is often done for import/loader tables. The data is first loaded in the "import"-table, then validated and then transported to the "real" tables. In such a scenario you can ignore the primary key on purpose. Because you already have a UK on this table it can't be such a scenario.
    For most other scenarios you should always add a PK. Ask critically why there is no PK on it. Is there a reason for it or was the table designer just not doing its job well?
    Btw: A UK is identical to a PK if the column is mandatory (NOT NULL). In this case you could simply change the constraint from UK to PK.

  • Deleting Primary Key --- High Priority -- Please help us

    There is a custom defined table which had two primary keys and then moved the same to production. Since we got some requiremnent we added two more primary keys in the table in development server. We also activated the same in Development server. Now we need to delete the recently added two primary keys. It is a most important custom table. It is not allowing us to delete.
    It gives us error message about lot of dependencies and foreign key used in other tables.
    Please help us resolve this issue. FULL POINTS WILL BE AWARDED FOR THE SOLUTION. please help us resolve the same. Bottle neck situation.
    Regards,
    Siddhartha

    Hi Siddhartha,
    http://www.ncsu.edu/it/mirror/mysql/doc/maxdb/en/3c/384c4005a99523e10000000a1550b0/content.htm
    If you are not sorting by the primary key ( E.g. using the ORDER BY PRIMARY key ... Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, ...
    http://www.sap-img.com/abap/performance-tuning-for-data-selection-statement.htm
    This links will help you to solve your  problem
    Thanks
    sunil

  • Impact Of Primary Key

    create table SEN_TEMP
      E_NO   NUMBER not null,
      E_NAME VARCHAR2(50),
      E_TEAM VARCHAR2(50)
    insert into sen_temp (E_NO, E_NAME, E_TEAM)
    values (1, 'A1', 'T1')
    insert into sen_temp (E_NO, E_NAME, E_TEAM)
    values (2, 'A2', 'T2')
    insert into sen_temp (E_NO, E_NAME, E_TEAM)
    values (3, 'A3', 'T3')
    Executing the Below
    SELECT *
    FROM sen_temp
    where rownum = 1
    order by e_no desc;
    Output
    E_NO   E_NAME  E_TEAM
    1          A1         T1
    Now am Gng to Add a Primary Key Constraint On the Column E_no
    alter table sen_temp add constraint pk_e_no primary key (e_no)
    Now Am Executing the Same query
    SELECT *
    FROM sen_temp
    where rownum = 1
    order by e_no desc
    But the
    Output Is
    E_NO   E_NAME  E_TEAM
    3          A3         T3
    Can Anyone Tell me, the way how the primary key is affecting the query

    Sen wrote:
    k den, why its returning e-no as 3 after adding a primary key..Most likely the execution plan has changed due to the addition of the primary key. See my example below:
    SQL> create table SEN_TEMP
      2  (
      3    E_NO   NUMBER not null,
      4    E_NAME VARCHAR2(50),
      5    E_TEAM VARCHAR2(50)
      6  )
      7  /
    Table created.
    SQL> insert into sen_temp (E_NO, E_NAME, E_TEAM)
      2  values (1, 'A1', 'T1')
      3  /
    1 row created.
    SQL> insert into sen_temp (E_NO, E_NAME, E_TEAM)
      2  values (2, 'A2', 'T2')
      3  /
    1 row created.
    SQL> insert into sen_temp (E_NO, E_NAME, E_TEAM)
      2  values (3, 'A3', 'T3')
      3  /
    1 row created.
    SQL> SELECT /*+gather_plan_statistics*/ *
      2  FROM sen_temp
      3  where rownum = 1
      4  order by e_no desc;
          E_NO E_NAME                                             E_TEAM
             1 A1                                                 T1
    1 row selected.
    SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  8hajz83tnvwnw, child number 0
    SELECT /*+gather_plan_statistics*/ * FROM sen_temp where rownum = 1
    order by e_no desc
    Plan hash value: 3862566870
    | Id  | Operation           | Name     | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT    |          |      1 |        |      1 |00:00:00.01 |       3 |       |    |     |
    |   1 |  SORT ORDER BY      |          |      1 |      1 |      1 |00:00:00.01 |       3 | 73728 | 73728 |          |
    |*  2 |   COUNT STOPKEY     |          |      1 |        |      1 |00:00:00.01 |       3 |       |    |     |
    |   3 |    TABLE ACCESS FULL| SEN_TEMP |      1 |      3 |      1 |00:00:00.01 |       3 |       |    |     |
    Predicate Information (identified by operation id):
       2 - filter(ROWNUM=1)
    Note
       - dynamic sampling used for this statement (level=2)
    25 rows selected.
    SQL> alter table sen_temp add constraint pk_e_no primary key (e_no)
      2  /
    Table altered.
    SQL> SELECT /*+gather_plan_statistics*/ *
      2  FROM sen_temp
      3  where rownum = 1
      4  order by e_no desc;
          E_NO E_NAME                                             E_TEAM
             3 A3                                                 T3
    1 row selected.
    SQL> SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(null,null,'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID  8hajz83tnvwnw, child number 0
    SELECT /*+gather_plan_statistics*/ * FROM sen_temp where rownum = 1
    order by e_no desc
    Plan hash value: 577902443
    | Id  | Operation                    | Name     | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    |   0 | SELECT STATEMENT             |          |      1 |        |      1 |00:00:00.01 |       2 |
    |*  1 |  COUNT STOPKEY               |          |      1 |        |      1 |00:00:00.01 |       2 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| SEN_TEMP |      1 |      3 |      1 |00:00:00.01 |       2 |
    |   3 |    INDEX FULL SCAN DESCENDING| PK_E_NO  |      1 |      1 |      1 |00:00:00.01 |       1 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM=1)
    Note
       - dynamic sampling used for this statement (level=2)
    25 rows selected.See how in the first case Oracle did a full table scan and in the second case it used an index? That's why your results are different.

  • How to create Primary key

    I want to insert HOSTID that has unique values in a new application in a primary key column in database.
    I am starting with h000000001
    and I want to go from that to h000000002
    and .... h0000000010 , 11, 12 etc etc.
    How do I do this?
    I did this:
    rs = stmt.executeQuery("select wlbmach_host_id from wlbmach order by wlbmach_host_id desc");
    // I am getting the greatest value eg: h000999999
    if (rs.next())
    getHostID = (String)rs.getString("wlbmach_host_id");
    //Get the h0009999999
    getStringNumber = getHostID.substring(1,10);
    //This gives me 9999999
    try
    {getNum = Integer.parseInt(getStringNumber);
    //change number to integer so I can add 1 to it
    getNum=getNum+1;
    getStringNumber=Integer.toString(getNum);//make that a string
    getHostID="h"+getNum;//add h to it
    }//try
    catch(Exception e)
    {System.out.println("NumberFormatException might have occured");%>
    else
         System.out.println("Assigning first HostID");
         getHostID = "h00000001";
    System.out.println("HostID is "+getHostID);
    But gives Exception:String index out of range: 10.. My column can take 10 varchar ??
    Can someone help .. Is this the right way to do it ?
    Is there a better way to generate primay keys?

    Why are you making life difficult??? Why not use the SEQUENCE object (if you are using Oracle)? You can retrieve next value by "Select sequencename.nextval from dual" as the query...you will get your number. Also, when two requests are made at the same time, Oracle takes care of this problem for you...you do not need to synchronize the method in JAVA. Do some research in this...I think you will like it.

Maybe you are looking for

  • Won't let me finish downloading on my pc. My pc says file is corrupt, why?

    It downloads fine, have done this upmteen millions of times. Even said to make firefox my default, but still my PC SAYS, file corrupt, can't finish

  • Error calling DLL in LabVIEW, but works in VC

    I compiled a DLL from Matlab, and then compiled a wrapper DLL in VC++. I tested the wrapper DLL in VC++, and it works fine, generating the correct output as in Matlab.  But when I call the wrapper DLL in LabVIEW, the first thing I noticed was that it

  • F-03 and fbra

    hi, what is f-03 clear gl account? what is the purpose of this tcode? what is fbra reset clearing? what is the purpose of this tcode? thanks rgds

  • SRWC 2.3 not supported in VDI 3.2.1

    Anyone know the latest on this limitation? Will it be lifted "soon"?

  • R6025 error when I start AA3

    I downloaded the free trial to test out this program and see if it is worth buying for me. I installed it and everything. When I started the program it told me this was a trial and I click ok. The next pop up says that it works better if it has its o