Two foreign keys in one single table

i have a table 'customers' with a 'customerid' as its primary key and another  table 'drinks' with a primary key 'drinkid'.now i have to create a table 'customerdrink' with its primary key as 'customerdrinkid' , and 'customerid' & 'drinkid' as
its two foreign keys.how can i write the script in sql server to connect the first two tables with the last one ie how can i relate one primary key(customerdrinkid) with two foreign keys(customerid and drinkid) in a single query?pls help me out!!!

>> I have a table 'customers' ...<< 
How nice for you, but where is the DDL? Oh, I see you are the Great and Wonderful “shubha2323” who does not have to follow Netiquette or treat anyone with minimal respect when he demands they do his work him! 
Where is what you already tried? Oh, the Great and Wonderful “shubha2323” does not try anything! His forum slaves should serve him! 
Do you understand how rude you are when you ignore the basic forum rules? 
CREATE TABLE Customers
(customer_id CHAR(16) NOT NULL PRIMARY KEY,
CREATE TABLE Drinks
(drink_id CHAR(10) NOT NULL PRIMARY KEY,
>> with a customer_id as its primary key and another table Drinks with a primary key drink_id. now I have to create a table 'customer_drink' with its primary key as 'customer_drink_id' <<
You do not know what single quotes mean in ANSI/ISO Standard SQL, or how to follow ISO-11179 Standards for data element names. And this is a stupid idea. You have a key!! Do you know what a key is? 
CREATE TABLE Drink_Preferences
(customer_id CHAR(16) NOT NULL 
  REFERENCES Customers(customer_id)
  ON DELETE CASCADE,
 drink_id CHAR(10) NOT NULL 
  REFERENCES Drinks(drink_id)
  ON DELETE CASCADE,
 PRIMARY KEY (customer_id, drink_id),
 etc
Stop posting until you have manners and you have read a book on RDBMS. 
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • Two foreign keys to one primary key

    I'm having trouble displaying information for two foreign keys in my table. My goal is to display the first and last name of both a Project Manager and Account Manager. I have a "Jobs" table linked to an "Employees" table.
    Jobs
    ProjectMgrID
    AcctMgrID
    Employees
    EmployeeID
    LastName
    FirstName
    Both ProjectMgrID(fk) and AcctMgrID(fk) are linked to EmployeeID(pk). When I build a query, I am not sure how to display both the FirstName and LastName fields for both. It only allows me to add them once, and when I add them twice it just displays the same information twice.
    Please help!

    Welcome to the forum!
    It looks like you'll need to join to EMPLOYEES twice.
    Something like the following:
    SELECT  e1.firstname
    ,       e1.lastname
    ,       e2.firstname
    ,       e2.lastname
    FROM    jobs
    JOIN    employees e1    ON e1.employeeid = jobs.projectmgrid
    JOIN    employees e2    ON e2.employeeid = jobs.acctmgrid
    ;

  • Multiple foreign keys to a single table

    Hi,
    I need to write an SQL sentence to bring a unique row formed from multiple foreign keys which are dependent on the same table. The two tables as follow:
    CREATE TABLE UNIDADMEDIDA (
    IDUNIDADMEDIDA NUMERIC(3) NOT NULL,
    DESCRIPCION VARCHAR2(128) NOT NULL,
    CONSTRAINT PKUM PRIMARY KEY(IDUNIDADMEDIDA)
    CREATE TABLE TRANSPORTE (
    IDBOLETA NUMERIC(12) NOT NULL,
    CORRELAVEHICULO NUMERIC(2) NOT NULL,
    TIPOVEHICULO NUMERIC(1),
    TIPOGASOLINA NUMERIC(1),
    CANTIDAD NUMERIC(8),
    RECORRIDOPROMEDIO NUMERIC(10,2),
    IDUMRECORRIDO NUMERIC(3),
    CONSUMOPROMEDIO NUMERIC(10,2),
    IDUMCONSUMOPROM NUMERIC(3),
    CONSUMOTOTALANUAL NUMERIC(10,2),
    IDUMCONSUMOTOT NUMERIC(3),
    CONSTRAINT PKTRANSPORT PRIMARY KEY(IDBOLETA, CORRELAVEHICULO),
    CONSTRAINT FKUMRECORRI FOREIGN KEY(IDUMRECORRIDO) REFERENCES UNIDADMEDIDA(IDUNIDADMEDIDA),
    CONSTRAINT FKUMCONSUMO FOREIGN KEY(IDUMCONSUMOPROM) REFERENCES UNIDADMEDIDA(IDUNIDADMEDIDA),
    CONSTRAINT FKUMCONSTOT FOREIGN KEY(IDUMCONSUMOTOT) REFERENCES UNIDADMEDIDA(IDUNIDADMEDIDA)
    The columns IDUMRECORRIDO, IDUMCONSUMOPROM and IDUMCONSUMOTOT depend on the table UNIDADMEDIDA (specifically from the IDUNIDADMEDIDA field). I need to bring back the description (DESCRIPCION field) from the different values stored in TRANSPORTE table.
    Thanks for your help!!!
    Mario

    Welcome to the forum!
    Have you thought about joining against the parent table three times to pick up each different description?
    SELECT  <COLUMN LIST>
    ,       UNI_A.DESCRIPCION
    ,       UNI_B.DESCRIPCION
    ,       UNI_C.DESCRIPCION
    FROM    TRANSPORTE
    JOIN    UNIDADMEDIDA    UNI_A   ON UNI_A.IDUNIDADMEDIDA = TRANPORTE.IDUMRECORRIDO
    JOIN    UNIDADMEDIDA    UNI_B   ON UNI_B.IDUNIDADMEDIDA = TRANPORTE.IDUMCONSUMOPROM
    JOIN    UNIDADMEDIDA    UNI_C   ON UNI_C.IDUNIDADMEDIDA = TRANPORTE.IDUMCONSUMOTOT
    ;It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You provided #2 partially. If you provide the rest we may be able to help you even further.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Two foreign keys reference on primary key

    There are two tables:
    1) table CALENDAR with primary key: cal_id
    2) table FACTS with some columns, two of them are dates: cal_id_start_process, cal_id_stop_process
    we want on physical layer create two foreign keys for cal_id_start_process and cal_id_stop_process columns reference on CALENDAR.cal_id
    When we create foreign key for cal_id_start_process: we choose this column and choose CALENDAR table and its primary key. But when we want to create foreign key for cal_id_stop_process - we cannot coose table CALENDAR again.
    Is this rigth, that only one column from table can reference on specified primary key in CALENDAR table?
    How to create two foreign key on one table primary key?

    More complex. In your example there'll be such SQL:
    select c.cal_id, f.cal_id_start, f.cal_id_stop
    from CALENDAR c, FACTS f
    where c.cal_id = f.cal_id_start and c.cal_id = f.cal_id_stop
    (It meens FACTS.cal_id_start = FACTS.cal_id_stop )
    In my case, I want for such join:
    select c1.cal_id, c2.cal_id, f.cal_id_start, f.cal_id_stop
    from CALENDAR c1, CALENDAR c2, FACTS f
    where c1.cal_id = f.cal_id_start and c2.cal_id = f.cal_id_stop
    Edited by: annylut on Dec 22, 2011 3:33 PM

  • Adding a foreign key to an access table

    I have set up two tables in access and I am using SQL insert
    with the form to populate the database. When I “submit”
    the form I receive the following error:
    Element CUST_ID is undefined in CUSTOMER_INFO.
    The error occurred in
    C:\Inetpub\wwwroot\spl_web_site\public_records\order_insert.cfm:
    line 23
    21 : <cfquery datasource="#odbc_datasource#"
    name="desc">
    22 : insert into rec_results (customer_info.cust_id,rec_desc)
    23 : values('#customer_info.cust_id#',
    24 : '#rec_desc#')
    25 : </cfquery>
    How do I get cust_id into the second table to be used as the
    foreigh key when it “has not been created (defined)” in
    the first table?

    If your cust_id is an autonumber primary key field in your
    first table, then you will have to create that record first, then
    retrieve the primary key value to be used as your foreign key in
    your second table, especially if you have foreign key constraints
    on the table. This is normal relational database behavior, since it
    isn't really possible to have a child if there is no parent. In
    this case, you will need some sort or SELECT between your two
    inserts in order to determine the newly created cust_id. Or, you
    may need some other means of gerating your unique PK value for
    cust_id outside of Access. If you do the SELECT method, you would
    do something like SELECT MAX(cust_id) FROM customer_info (assuming
    that cust_id is generated sequentially), and you should enclose all
    three database transactions within CFTRANSACTION tags so that you
    don't accidentally grab the wrong cust_id from another simultaneous
    transaction.
    Phil

  • Taking data from two different server in a single table

    Hi All,
    can u plz tell me i want take a data from a two different server in a single table
    Thanks,
    Bell.

    Again, you have written the same sentence. I have 2 servers Server1 and Server2 and one table called my_table (You or God knows where this table is).
    Now tell us what you want to do ?
    Sidhu
    http://amardeepsidhu.blogspot.com

  • Foreign Keys for a Logical Table

    Hi All,
    I want to know in which scenarios we create the Foreign Keys for a Logical Table. Once we create the foreign key for the logical table, does it mean that it will automatically override if any joins are there.
    Physical Table A, B ( no physical joins)
    Logical Table A, B (logical join B(Dim)-->A(Fact))
    created the foreign key in logical table A with B .(A.1=B.1)
    Will the rpd generate sql with A.1=B.1 join condition for reports.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    http://tinypic.com/r/jq1gkz/6
    Thanks,
    Virat

    In general when we go complex joins in Physical layer we go for Logical foreign key joins in BMM layer, best examples is SCD Type-II.
    Physical Table A, B ( no physical joins)
    -->You need to have a physical join so that this can be override by BMM layer
    created the foreign key in logical table A with B .(A.1=B.1) Will the rpd generate sql with A.1=B.1 join condition for reports.
    -->Yes you can see this join in BI Physical query.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    -->2 cases: 1)You need to delete existing logical joins 2) You might not have join in physical layer.
    Hope this helps
    Let me know for issues
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM
    BTW: You got very good name, why dont you update in your profile to see your name instead of some number
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM

  • Two Primary keys on one table

    We are at the end of completing a project and we ran into a last minute bug. We are using two primary keys on a table to form a unique key. The problem we have is the program hangs up and gives us the following error,
    ORA-20001: Error in DML: p_rowid=CUA, p_alt_rowid=SIT_ID, p_rowid2=, p_alt_rowid2=. ORA-01422: exact fetch returns more than requested number of rows,
    probably meaning we only have one key setup in the DML
    processing when our table has two.
    we created a process with the Primary key set up in the DML but how does the secondary key column value work and is that what it's used for,because we tryed with no success. Is there a way around this problem without having to change our table by inserting only one primary key.
    Thanks in advance.
    Garry

    I am facing a similar problem , I used the two primary keys for navigating to the form page (forms with reports) so that the form page may display distinct records.
    Its not posing any error but its not showing the value of other columns associated with that record.
    Only the columns contained in the page item in the form page , that's are used as primary keys or that have been specified in the navigation part of the report page, are being shown ,
    Like for example I have got 5 columns
    a,b,c,d,e out of which a and b are my primary keys .
    I am using these to fetch values in the form page of forms with reports.
    We can specify three keys at the most , in my case I am having two , if in place of the third key I specify some column then in the form page it displays the correct record details of the three columns specified( 2 keys and one simple column), and it doesn't displays the value of other columns.
    Please help me out of this .

  • Questions about creating a foreign key on a large table

    Hello @ll,
    during a database update I lost a foreign key between two tables. The tables are called werteart and werteartarchiv_pt. Because of its size, werteartarchiv_pt is a partitioned table. The missing foreign key was a constraint on table werteartarchiv_pt referencing werteart.
    Some statistics about the sizes of the mentioned tables:
    werteart 22 MB
    werteartarchiv_pt 223 GB
    werteartarchiv_pt (Index) 243 GB
    I tried to create the foreign key again, but it failed with the following error (Excuses for the german error message):
    sqlplus ORA-00604: Fehler auf rekursiver SQL-Ebene 1
    sqlplus ORA-01652: Temp-Segment kann nicht um 128 in Tablespace TEMPS00 erweitert
    The statement I used:
    alter table werteartarchiv_pt
    add constraint werteartarchiv_pt_fk1
    foreign key (schiene, werteartadresse, merkmale)
    references werteart (schiene, werteartadresse, merkmale)
    on delete cascade
    initially deferred deferrable;
    So the problem seems to be, that Oracle needs a lot of temporary tablespace to generate the foreign key and I do not know how much and why.
    My questions now are, and hopefully someone is here, who can answer all or a part of it:
    1) Why does Oracle need temporary tablespace to create the foreign key? The foreign key uses the same columns like the primary key.
    2a) Is it possible to tweak the statement without using the temporary tablespace?
    2b) If it is not possible to avoid the usage of the temporary tablespace, is there a formula how to calculate the needed temporary tablespace?
    3) Is it possible to modify data in the tables while the foreign key is created or is the whole table locked during the process?
    Any help or hint is appreciated.
    Regards,
    Bjoern

    RollinHand wrote:
    My questions now are, and hopefully someone is here, who can answer all or a part of it:
    1) Why does Oracle need temporary tablespace to create the foreign key? The foreign key uses the same columns like the primary key.Because it's validating the data to ensure the foreign key won't be violated. If you had specified ENABLE NOVALIDATE when creating it then the existing data in the table wouldn't need to be checked and the statement should complete instantly (future data added would be checked by the constraint).
    http://download.oracle.com/docs/cd/B28359_01/server.111/b28310/general005.htm
    Search for "Enable Novalidate Constraint State"

  • I need to have multiple foreign keys on one column, can Designer do this?..

    Basically I've a table that needs to link to three other tables. As far as I can tell Designer will only let me have the foreign keys on seperate columns;
    Column_1 - FK1
    Column_2 - FK2
    Column_3 - FK3
    I think it's a much better database design is to have all three link to one column and have a Type column denoting which table to references
    Column_1 - FK1, FK2, FK3
    Column_2 - Type (FK1, FK2, FK3)

    Can you tell us more about the problem you're trying to solve?
    Thanks, George

  • Foreign Keys and import of tables (ORA-02297)

    How can i get all the foreign keys for a particular schema, basically i'm trying to import tables into a particular schema so i'm trying to disable the constraints, truncate the table , import data and then enable the constraints.
    but i'm having error like these when i disable all the constraints in this particular schema
    Table altered.
    alter table STANDINGS disable constraint P_STANDINGS
    ERROR at line 1:
    ORA-02297: cannot disable constraint (SCDAT.P_STANDINGS) - dependencies exist
    alter table STANDPMTS disable constraint P_STANDPMTS
    ERROR at line 1:
    ORA-02297: cannot disable constraint (SCDAT.P_STANDPMTS) - dependencies exist

    I use a dynamic SQL-Plus script to generate all the constraints for a schema. I then run this SQL to disable the constraints. Sometimes need to run the script more than once depending on the order the constraints are disabled. Once your scripts runs clean, then you can truncate your tables, import your data, and re-enable constraints.
    To re-enable, just use and editor to do REPLACE DISABLE WITH ENABLE....
    Here is sample of my dynamic sql. Needs to be run as SYSDBA...
    set heading off;
    spool c:\disable_constraints.sql;
    select 'ALTER TABLE ' || owner || '.' || table_name || ' DISABLE CONSTRAINT ' || constraint_name || ';'
    from dba_constraints
    where owner = '<owner_name>';
    spool off;
    Hope that helps..

  • Group Two Adjacent Clips Into One Single Clip?

    It seems like there ought to be an easy way to do this, but I can't seem to find it.
    I'd like to take two (AV) clips that are adjacent on the time line, and group/merge/copy (not sure what term to use) them together into one single clip. That so that I can then apply a single continuous movement, rotation, opacity changes, and so forth to the resulting single clip.
    If any of you are familiar with The audio-editing program called Digital Performer, what I'm looking for would be the AV analogy with Performer's "Merge Soundbites" operation.
    Anybody know how to do that?
    Thanks folks!

    Yes, nesting is the answer. select the clips you want to nest go to Sequence / Nest items / give it a name and there you'll got your nested sequence as a separate file in the browser.
    What a coincidence! I just nested a series of stills in order to be able to animate their size over time.

  • Foreign-key autocreation in child table giving issue in the application

    Hi,
      I am facing an issue with partitioning a table that foreign key relationship is created on the original table with interim table. This gives exception in the application because of its existence. Please suggest me how to get rid of this issue.
    Let's say my table T_TABLENAME has to be partitioned. It has a child table T_CHILD_TABLENAME which references (FK_T1) ID column of T_TABLENAME.
    While partitioning, COPY_TABLE_DEPENDENTS function copies/creates the key/index/trigger objects for the interim table. [I need copy_constraints => TRUE in COPY_TABLE_DEP call], Fine.
    But, after partitioning is done, the foreign key (TMP$$_FK_T1) object exists with the child table which should absolutely not happen as this forms dependency with interim table as well along with parent table.
    Here my script goes:
    i) Creating interim table
    CREATE TABLE T_TABLENAME_PT
    PARTITION BY RANGE (CREATED_DATE)
    (PARTITION P_2007 VALUES LESS THAN (TO_DATE('01-JAN-2008','dd-MON-yyyy')),
    PARTITION P_2009 VALUES LESS THAN (TO_DATE('01-JAN-2010','dd-MON-yyyy')),
    PARTITION P_2011 VALUES LESS THAN (TO_DATE('01-JAN-2012','dd-MON-yyyy')),
    PARTITION P_2012 VALUES LESS THAN (TO_DATE('01-JAN-2013','dd-MON-yyyy')),
    PARTITION P_RECENT VALUES LESS THAN (MAXVALUE))
    AS SELECT * FROM T_TABLENAME WHERE 1=2;
    ii) Partitioning Script
    declare
      v_username varchar2(50);
      v_exception varchar2(220);
      l_num_errors PLS_INTEGER;
      v_source_table  varchar2(35) := 'T_TABLENAME';
      v_interim_table varchar2(35) := 'T_TABLENAME_PT';
    BEGIN
      select USERNAME into v_username from USER_USERS where rownum <= 1;
      begin
          DBMS_REDEFINITION.CAN_REDEF_TABLE(v_username, v_source_table, DBMS_REDEFINITION.CONS_USE_PK);
          DBMS_REDEFINITION.START_REDEF_TABLE(
            uname      => v_username,
            orig_table => v_source_table,
            int_table  => v_interim_table);
          DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(
            uname      => v_username,
            orig_table => v_source_table,
            int_table  => v_interim_table,
            copy_indexes => 1,
            copy_triggers => TRUE,
            copy_constraints => TRUE,
            copy_privileges => TRUE,
            ignore_errors => TRUE,
            num_errors => l_num_errors);
          DBMS_REDEFINITION.SYNC_INTERIM_TABLE(v_username, v_source_table, v_interim_table);
          begin
           DBMS_REDEFINITION.FINISH_REDEF_TABLE(
            UNAME      => v_username,
            ORIG_TABLE => v_source_table,
            INT_TABLE  => v_interim_table);       
         EXCEPTION
         WHEN OTHERS THEN
           DBMS_REDEFINITION.ABORT_REDEF_TABLE(
            UNAME      => v_username,
            ORIG_TABLE => v_source_table,
            INT_TABLE  => v_interim_table);
          end;     
          exception
              when others then
                v_exception :=substr(SQLERRM,1,150);
      end;
    exception
      when others then
        v_exception := substr(SQLERRM,1,175);
    END;

    Thanks for your information. I am using Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit.
    1) I am logging the exceptions in a logger table.
    2) If CAN_REDEF_TABLE gives exception, flow goes to the final EXCEPTION block and program terminates. So if no exceptions, the other steps comes into the flow of execution.
    Complete Details
    (1) Parent Table (existing): T_SOH_SUBREQ_INSTALLATION_ADDR
    create table T_SOH_SUBREQ_INSTALLATION_ADDR
      ACCOUNT_ADDRESS_ID  NUMBER(10),
      SUBREQ_ADDRESS_ID   NUMBER(10) not null,
      COMMUNITY_ID        NUMBER(10),
      STREET_ID           NUMBER(10),
      BUILDING_ID         NUMBER(10),
      CREATED_USER_ID     VARCHAR2(40) not null,
      MODIFIED_USER_ID    VARCHAR2(40) not null,
      CREATED_DATE        TIMESTAMP(6) not null,
      MODIFIED_DATE       TIMESTAMP(6) not null,
      DELETION_STATUS     CHAR(1) not null
    alter table T_SOH_SUBREQ_INSTALLATION_ADDR
      add constraint PK_T_SOH_SUBREQ_INST_ADDR primary key (SUBREQ_ADDRESS_ID);
    alter table T_SOH_SUBREQ_INSTALLATION_ADDR
      add constraint FK_T_SOH_SUBREQ_INSTALLATIO624 foreign key (ACCOUNT_ADDRESS_ID)
      references T_SOH_ACCT_INSTALLATION_ADDR (ACCOUNT_ADDRESS_ID);
    (2) Child Table (existing): T_SOH_SUBREQ_LINKED_INST_ADDR
    create table T_SOH_SUBREQ_LINKED_INST_ADDR
      CREATED_DATE      TIMESTAMP(6) not null,
      CREATED_USER_ID   VARCHAR2(40) not null,
      MODIFIED_DATE     TIMESTAMP(6) not null,
      MODIFIED_USER_ID  VARCHAR2(20) not null,
      DELETION_STATUS   CHAR(1) not null,
      SUBREQ_ADDRESS_ID NUMBER(10) not null,
      SUBREQUEST_ID     NUMBER(10) not null,
      CIRCUIT_POINT     NUMBER(10)
    alter table T_SOH_SUBREQ_LINKED_INST_ADDR
      add constraint PK_T_SOH_SUBREQ_LINK_INST_ADDR primary key (SUBREQ_ADDRESS_ID, SUBREQUEST_ID);
    alter table T_SOH_SUBREQ_LINKED_INST_ADDR
      add constraint FK_T_SOH_SUBREQ_LINKED_INST626 foreign key (SUBREQ_ADDRESS_ID)
      references T_SOH_SUBREQ_INSTALLATION_ADDR (SUBREQ_ADDRESS_ID);
    (3) Partitioning is done on Parent Table
    CREATE TABLE T_TMP_PARTITION_LOGS
      LOG_MSG  VARCHAR2(250),
      LOG_TIME TIMESTAMP(6)
    CREATE TABLE T_SOH_SUBREQ_INSTALL_ADDR_PT
    PARTITION BY RANGE (CREATED_DATE)
    (PARTITION P_2007 VALUES LESS THAN (TO_DATE('01-JAN-2008','dd-MON-yyyy')),
    PARTITION P_2009 VALUES LESS THAN (TO_DATE('01-JAN-2010','dd-MON-yyyy')),
    PARTITION P_2011 VALUES LESS THAN (TO_DATE('01-JAN-2012','dd-MON-yyyy')),
    PARTITION P_2012 VALUES LESS THAN (TO_DATE('01-JAN-2013','dd-MON-yyyy')),
    PARTITION P_RECENT VALUES LESS THAN (MAXVALUE))
    AS SELECT * FROM T_SOH_SUBREQ_INSTALLATION_ADDR WHERE 1=2;
    insert into t_tmp_partition_logs(log_msg,log_time) values('01_CreateTable: T_SOH_SUBREQ_INSTALL_ADDR_PT Table Created', systimestamp);
    (4) Script for REDEFINITION
    declare
      v_username varchar2(50);
      v_exception varchar2(220);
      l_num_errors PLS_INTEGER;
      v_source_table  varchar2(35) := 'T_SOH_SUBREQ_INSTALLATION_ADDR';
      v_interim_table varchar2(35) := 'T_SOH_SUBREQ_INSTALL_ADDR_PT';
      v_file_name     varchar2(20) := '02_Redefine';
    BEGIN
      insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name || '.sql --> Starts', systimestamp);
      select USERNAME into v_username from USER_USERS where rownum <= 1;
      insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name || ': UserName-'|| v_username, systimestamp);
      begin
          DBMS_REDEFINITION.CAN_REDEF_TABLE(v_username, v_source_table, DBMS_REDEFINITION.CONS_USE_PK);
          insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': '|| v_source_table ||' After CAN_REDEF_TABLE', systimestamp);
          DBMS_REDEFINITION.START_REDEF_TABLE(
            uname      => v_username,
            orig_table => v_source_table,
            int_table  => v_interim_table);
          insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': '|| v_source_table ||' After START_REDEF_TABLE', systimestamp);
          DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(
            uname      => v_username,
            orig_table => v_source_table,
            int_table  => v_interim_table,
            copy_indexes => 1,
            copy_triggers => TRUE,
            copy_constraints => TRUE,
            copy_privileges => TRUE,
            ignore_errors => TRUE,
            num_errors => l_num_errors);
          insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': '|| v_source_table ||' After COPY_TABLE_DEPENDENTS - l_num_errors:' || l_num_errors, systimestamp);
          DBMS_REDEFINITION.SYNC_INTERIM_TABLE(v_username, v_source_table, v_interim_table);
          insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': After SYNC_INTERIM_TABLE on '|| v_source_table, systimestamp);
          begin
           DBMS_REDEFINITION.FINISH_REDEF_TABLE(
            UNAME      => v_username,
            ORIG_TABLE => v_source_table,
            INT_TABLE  => v_interim_table);       
          insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': After FINISH_REDEF_TABLE on '|| v_source_table, systimestamp);
         EXCEPTION
         WHEN OTHERS THEN
           DBMS_REDEFINITION.ABORT_REDEF_TABLE(
            UNAME      => v_username,
            ORIG_TABLE => v_source_table,
            INT_TABLE  => v_interim_table);
           insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': Aborted '|| v_source_table, systimestamp);
          end;     
        insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||': '|| v_source_table ||' redefined', systimestamp);
          exception
              when others then
                v_exception :=substr(SQLERRM,1,150);
                insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||'-EXCEPTION:'|| v_source_table ||'-' || v_exception, systimestamp);
      end;
      insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||'.sql <-- Ends', systimestamp);
    exception
      when others then
        v_exception := substr(SQLERRM,1,175);
        insert into t_tmp_partition_logs(log_msg,log_time) values(v_file_name ||'-EXCEPTION:' || v_exception, systimestamp);
    END;
    ==> NOW THE ISSUE
    My child table T_SOH_SUBREQ_LINKED_INST_ADDR is having another foreign key column TMP$$_FK_T_SOH_SUBREQ_LIN4 with the interim table T_SOH_SUBREQ_INSTALL_ADDR_PT.

  • Is it possible to deploy two different EJBs in one single descriptor file?

    Hi, I'm working with two EJBs I wanna deploy them in one single jar, so my question here is, is it possible to deploy two or more EJBs within the same xml descriptor file?, if so, could you please give me an example of it?, I'm working with Stateless session beans, thanks in advance.

    You can have as many beans in an EJB deployment descriptor as you like - i think, i have not run into a limit yet...
    <ejb-jar>
    <enterprise-beans>
    <session>
    <description>Session Bean ( Stateless )</description>
    <display-name>BEanOne</display-name>
    etc...
    </session>
    <session>
    <description>Session Bean ( Stateless )</description>
    <display-name>BeanTwo</display-name>
    etc...
    </session>
    </enterprise-beans>
    </ejb-jar>
    m

  • How should i use the two results sets in one single report data region?

    Hi frnz,
     I have to create a report using the below condition...
    Here my given data  set query gives you the two result sets ,so how should i use that two result sets information in single report....when i accessing that data set query it will take the values off the first result set not for the second result set.
    without using sub report and look up functionality..... if possible
    is there any way to achieve this.....Please let me know..
    Thanks!

    You cant get both resultsets in SSRS. SSRS dataset will only take the first resultset
    you need to either create them as separate queries or merge them into a single resultset and return with ad additional hardcoded field which indicates resultset (ie resultset1,resultset2 etc)
    Then inside SSRS report you can filter on the field to fetch individual resultsets at required places. While merging you need to make sure metadata of two resultsets are made consistent ie number of columns and correcponding column data types should be same.
    In absence of required number of columns just put some placeholders using NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Old second generation ipod shuffle not working with itunes

    So i recently found a old ipod shuffle 2nd generation but could not find the charger/sync cable so i found a usb to audio jack. i pluged everything in correclty but it saids the usb connection is an unknown device and itunes doesnt connect it or reco

  • Aperture import automator workflow available

    I recently put together an Aperture import workflow in Automator which I thought other people might find useful, it can be downloaded with instructions here: http://tonyswash.info/ImportPlugin.zip What this does is act as a plug-in for Image Capture.

  • Help,Help,Help...Some songs DO NOT play???

    Help,Help,Help...I don`t remeber what updates but it stopped playing some songs that wre playing before...AC/DC Back in Black was transfered from original CD to iTunes and all songs were playing fine until I installed a new OS (4.0something,do not re

  • Planned Order No. Reference in PR

    Hi all, I want to find the planned order number in the PR generated converting a planned order manually. I searched for the answer but could not find the correct answer. Pls, help me.. Regards, Karteek.

  • 403-Forbidden exception for Enterprise Service

    Hi, A week back, through SOA Manager I had configured a enterprise service. Everything was looking good. The service was active and I could consume the service (through a SOAP Client) Just yesterday, when I tried accessing the service again, I am get