How to create a primary key

Hello - New to Oracle and was wondering what is a good way to create an auto-incrementing primary key for a table. I have done this so far:
Created a new sequence cst_swq begin with 1 increment by 1.
CREATE OR REPLACE TRIGGER CST_TRIG
BEFORE INSERT
ON COOKIE_SALES
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
SELECT CST_SEQ.nextval INTO NEW.SALE_ID FROM dual;
This does not really work for me. Help with the code or a better idea to create primary key is much appreciated, thank you.

adi26 wrote:
This does not really work for me. What does that mean?
In which way does this approch not meet your requirements?
BTW: after 200+ posts you should have learned how to use tags...
bye
TPD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How to create one primary key for each vendor

    Hi all
    i am doing IDOC to jdbc scenario
    i am triggering idoc from R/3 and the data is going into DB table vendor through XI.
    structures are as follows:
    sender side: ZVendorIdoc (this is a customized IDOC , if i triger IDOC for multiple vendors then it triggers only 1 idoc with multiple segment )
    Receiver side:
    DT_testVendor
        Table
            tblVendor
                action UPDATE_INSERT
                access                     1:unbounded
                    cVendorName         1
                    cVendorCode        1
                    fromdate                1
                    todate                    1
                 Key1
                    cVendorName         1
    if i trigger idoc for multiple vendors ,for example vendor 2005,2006 and 2010 . then i can see that the only key comes from the very first field (2005) and the whole record for vendor 2005,2006 and 2010  goes into the table with this(2005) as a primary key
    now again if i send data for these three vendor 2005, 2006 , 2010, in which record for the vendor 2005 is same and for 2006 and 2010 are different than it takes 2005 as a primary key and it does not update the data in the table.
    my requirement is like this:   for each vendor there should be one unique key assigned.
                                              for above said example there should come three keys one for each vendor .
    could you please help me how to do this???????????

    Hi,
      In Mapping Make the statement is 0-unbounded.For each vendor create a statement.This will solve your problem.
    Regards,
    Prakasu.M

  • How to create a primary key by 2 columns in sql??

    as title
    thx a lot.

    Chris,
    Well you have two basic ways. One is to issue an alter table command and define a PRIMARY KEY (also called a PK). The other is to create a UNIQUE index. The PRIMARY KEY creates an index anyway, though I prefer to just use unique indexes as you can specify more options in this manner. A table can only have 1 PK where as you can have multiple UNIQUE indexes. I also do not combine the PK definition directly into the CREATE TABLE command, as normally one would keep a seperate PK script, even if they did contain only unique indexes commands and not PK alter table commands.
    Anyway, below are the two methods of making a PK/Unique object for your table. The table name used here is T1 ...
    Method #1 (Primary Key)
    ALTER TABLE T1 DROP PRIMARY KEY;
    ALTER TABLE T1 ADD PRIMARY KEY
    (Column_1,Column_2, ...)
    STORAGE
         NEXT 512K
         MINEXTENTS 1
         MAXEXTENTS UNLIMITED
         PCTINCREASE 0
    Method #2 (preferred) : Unique Index
    DROP INDEX PK_T1;
    CREATE UNIQUE INDEX PK_T1 ON T1
    (Column_1,Column_2, ...)
    TABLESPACE INDX
    PCTFREE 10
    STORAGE
         INITIAL 1M
         NEXT 512K
         MINEXTENTS 1
         MAXEXTENTS UNLIMITED
         PCTINCREASE 0
    It's always best to define the storage clause for both the create table and it's indexes.
    Hope this helps ya,
    Tyler

  • How to create a primary key or foreign key

    in the table student, sid should be the primary key
    in the table prerequisite cnum should be the foreign key and prereq the primary key
    please help me with the syntax thanks.

    As I said in your other post, it's all in the docs, go first to http://tahiti.oracle.com and try to find the answer yourself
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/clauses3a.htm#1002630

  • How do I use Primary Key and RowID in Materialized View Logs and MVs

    How do I use Primary Key and RowID in Materialized View Logs and Materialized Views????
    I don’t understand in the Materalized View Logs the diference between Primary Key and RowID. Besides, I could choose both Primary Key and RowID.
    When I have to use RowID?? Why?? And Primary Key??? And both, Primary Key and RowID????
    Thank you very much!

    Yes, I have already read it...
    But for example I don’t Understand:
    This is the example 8-1
    CREATE MATERIALIZED VIEW LOG ON products
    WITH SEQUENCE, ROWID
    (prod_id, prod_name, prod_desc, prod_subcategory, prod_subcat_desc, prod_
    category, prod_cat_desc, prod_weight_class, prod_unit_of_measure, prod_pack_
    size, supplier_id, prod_status, prod_list_price, prod_min_price)
    INCLUDING NEW VALUES;
    But if I create a Materialized View with TOAD if I choose a KEY field I receive the error:
    ORA-12026: invalid filter column detected
    Then I have to take out the Key (in the above example prod_id)
    And then the script is
    CREATE MATERIALIZED VIEW LOG ON products
    WITH ROWID, SEQUENCE, PRIMARY KEY!!!!!!!!!!!!!!!!!!!!
    (prod_id, prod_name, prod_desc, prod_subcategory, prod_subcat_desc, prod_
    category, prod_cat_desc, prod_weight_class, prod_unit_of_measure, prod_pack_
    size, supplier_id, prod_status, prod_list_price, prod_min_price)
    INCLUDING NEW VALUES;
    I have PRIMARY KEY in the definition (I don’t choose it) and I don’t have the prod_id field
    Why is it????
    Note: If I execute the script to create the MV Log manually the PRIMARY KEY option NO IS in the script and the prod_id field either is in the script.
    And on the other hand,
    What is this:
    CREATE MATERIALIZED VIEW LOG ON sales
    WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON times
    WITH ROWID;
    CREATE MATERIALIZED VIEW LOG ON customers
    WITH ROWID;
    These MATERIALIZED VIEW LOG contain any fields????
    Or it contain the primary key fields of this tables (sales, times and customers)??? Then, Why is it ROWID instead of PRIMARY KEY????
    Thanks!

  • How to create a block key default for documents created by MIRO?

    Hi All,
    How to create a block key (BSEG-ZLSPR) default for documents created by MIRO?
    Could anyone tell me?
    Thanks
    Gandalf

    HI,
    The payment block--BSEG-ZLSPR can be made defaulted by two  ways.
    Means you want to fix one value all the times for the same ,you have to do the same in Vendor master
    ie in the Vendor Master in the Payment Transactions Selection screen. make the Payment Block you want to be defaulted in MIRO.
    you can do for all vendor master in mass change -- XK99.(LFB1)
    if you are not OK with the Above .then there is another way to do the same
    it is by Screen layout setting in SHD0
    in this enter the Transaction MIRO and create a Transaction variant Z*** and click on create
    and also create a Screen variant in OMLRLIST 
    T code MIRO
    Screen variant name Z**
    Program-SAPLFDCB
    Screen Number 0020
    and create it .
    in creating ---enter the default value in the Payment block and in the varinat just check the box w.content
    KNow in SHd0 add this screen variant for the above Trasaction variant
    and then activate this trasaction variant by going into the tab Standard variants.
    so that when ever you do miro this variant will be called and you can get this payment block defaulted.
    hope so it helps
    Regards
    Anjanna

  • 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

  • How to create a shortcut key for email ?

    how to create a short key on mac book pro

    You do not say what OS X you are running.  If it is 10.8.3 you simply can have Mail a 4-finger swipe away.
    No short key neccessary?
    If some earlier OS X see >System Preferences>Keyboard>KeyboardShortcuts>ApplicationsShortcuts

  • How to create a account key for application type M ?

    Hi Guys,
    How to create a account key for application type M ? and link the same with
    Gl account.
    thanks.

    Hi
    Please create the account keys or transaction keys in
    SPRO-> IMG-> MM-> Purchasing-> Conditions-> Define Price Determination Process-> Define Transaction/Event Keys
    Thanks & Regards
    Kishore

  • HOw to create a foreign key in Derby netbeans 5.0

    I am trying to create a primary key in my database/web java application. I am using netbeans 5.0 and java vr5. I have put the following line in the DERBY SQL editor:
    ALTER TABLE staff ADD CONSTRAINT staff_fk FOREIGN KEY (staffID) REFERENCES staff (staffID);
    this returns Error: staffID is not a colum in Table of VTI skill
    However I have got a staffID Column in the table. Is this a BUG in netbeasn 5.0 or am I doing this incorrectly please can anyone show me a way round this problem. Iam suppose to use CMP or something please help.
    thanks in advance

    ALTER TABLE "staff" ADD CONSTRAINT "staff_fk" FOREIGN KEY ("staffID") REFERENCES "staff" ("staffID");

  • How i can Find primary key combination?

    Hi,
    I have small doubt how i can find primary key combination for a record in siebel application.( For example Opportunity list applet or Account list applet or etc.. what is the primary key combination and how i can find that combination for a particular record)
    Thanks & Regards

    Hi
    From the applet Identify the Business Component (BC)
    From the BC idnetify the table, and the property user key sesuence will give you the proper combination. Column conflic_id is used for handling remote synchronization.
    For BC based on S_PARTY, such as COntact, the table mentionned in User PRop will give your the main table used in this case.
    Best Regards
    EvtLogLvl

  • Creating a primary key with the parallel option and the tablespace option

    I know I can create a unique index with these options and then make the primary key with the "using index" clause. anyway to do this and skip the create unique index and just create the primary key ?

    SQL> ALTER TABLE t
      2  ADD CONSTRAINT pk_t
      3  PRIMARY KEY (testcol)
      4  USING INDEX
      5  TABLESPACE example
      6  PARALLEL (DEGREE 2);
    PARALLEL (DEGREE 2)
    ERROR at line 6:
    ORA-03001: unimplemented featureYou can name the tablespace but you must do an alter index thereafter.

  • How to create a unique key using two or more attributes?

    how to create a unique key using two or more attributes ?

    The following example illustrate how to create a unique key using two or more attributes/fields
    Scenario: Implementing Unique Key on ManagerID & Location ID in DepartmentEO(Department Table)
    Step#1: Open the Desired Entity Object “DepartmentEO”. Go to Overview tab & Click “General” Finger tab.
    Step#2: Expand “Alternate Keys” section & click “+”.
    Step#3: In the Pop-up wizard, Enter a name for alternate Key “Unique_Manager_X_Location”.
    Step#4: Select the desired attributes/fields from available list & Shuffle to right side.
    Step#5: Now go to “Business Rules” finger tab.
    Step#6: Select “Entity Validators” in the list & click “+” to add a new entity level validation rule.
    Step#7: In the Pop-up, Select “Rule Type” as Unique Key
    Step#8: In the “Rule Definition” tab select the key “Unique_Manager_X_Location”created.
    Step#9: Now go to “Failure Handling” tab, and click the Magnifier Icon .
    Step#10: If the key is not already created then in the “Select Text Resource” Popup, Using the functional design document, Enter display value, Key and Description. And click “Save & Select” Button.
    Step#11: Now Click “OK”.

  • How to Create a Restricted Key Figure in BO Webi Report

    Hi Experts,
    Please tell me How to Create a Restricted Key Figure in BO Webi Report.
    Thanks in Advance.
    Regards,
    Rafi

    Hi,
    1. Define a new measure in the designer.
    2. In the select clause give the reference to the key figure on which restriction to be applied.
    For example
    @Select(Key Figures\Number of Records)
    3. In the where clause, give the MDX expression for the filter to be applied.
    For example
    <FILTER KEY="[0PURCH_ORG].[LEVEL01]">
    <CONDITION OPERATORCONDITION="InList">
    <CONSTANT CAPTION="HAS"/>
    </CONDITION>
    </FILTER>
    Regards

  • Can I create constraints "Primary key - Foreign key" on materialized views?

    Hello!
    Can I create constraints "Primary key - Foreign key" on materialized views like on tables?
    My purpose - is to make DB schema "COPY" with set of materialized views or tables, which take data from time to time from other tables situated.into another schema "ORIGINAL".
    Also - I want to use reporting tool, like Crystal Reports, to make nice reports from schema "COPY". To make nice reports, I need primary-foreign relationships between materialized views or tables in schema "COPY".
    Is it possible to use materialized views?
    Or I should use only tables to get such result?
    Thank you in advance.
    Edited by: kogotok1 on Dec 3, 2010 5:01 PM

    What happens when you try it? Or search the manuals.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/statements_6002.htm#i2105365
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10706/repmview.htm#REPLN360

Maybe you are looking for

  • Struts tiles to create event based loading of tiles on a JSP

    Hi All, I am working on a web app where I am using struts tiles to create my JSPs. I have tiles for header, footer & nav bar. Now I want to break up my JSP body in multiple tiles. It is required that I insert only one body tile initially, say body1,

  • ALV ERROR in Function Module Fieldcatlog Merge .

    Hi I have added 2 more fileds in internral table . this is alv report there is no syntax error . i have user function module CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE' EXPORTING i_program_name = w_repid i_internal_tabname = 'T_BSIK' I_STRUCTURE_NAM

  • How to get a Verilog Simulator

    Hi, I am a Lamar University student. I read in few threads here that students can get a free copy of NC Verilog or VCS verilog simulator at free of cost for OpenSparc project. I searched through google for 2 days but still I am not able to find a lin

  • HELP!!! main page is in gibberish!!

    okay when i try to log onto http://192.168.1.1/ the language is in some kind of foreign language. i tried to translate it to everything but its in none of the languages. I bought this router yesterday and its been like that ever since Im running a Wi

  • Mail unread Count out of Synch

    I synch my mail with an Exchange server. My Inbox and two other folders alway show 1 unread (Inbox has got 3 unread). "Mark All Messages as Read" doesn't change the unread count. Rebuild, restart mail doesn't help neither- Any clue? Michael