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
Similar Messages
-
Hi,
I have a table (num of rows 60,00,000). I am adding a foreign key constraint
through alter table option but it is taking very long time to complete...
Any other methods to enhance the performance......Please read about [url http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96524/c22integ.htm#6719]Constraint States in the manual.
-
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,
ViratIn 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 -
Adding a foreign key based on composite key of other table
Hi All,
I have two tables one named 'products' (T1) and other 'codes' (T2). The product_code column in T1 needs to reference code_id values where code_type="STREET" from T2. T2 primary key is based on two columns 'code_id' and 'code_type'.
The issue is t1 table has only one of the column from T2. i.e; product_code (T1) corresponds to code_id (T2) and code_type should always have value "STREET"
I am not getting how to implement the foreign key constraint on T1 in such scenario. Hope my explanation is clear. Feel free to ask for more clarifications. Please suggest.
Thanks
Edited by: user5108636 on 26/09/2011 21:20user5108636 wrote:
Hi All,
I have two tables one named 'products' (T1) and other 'codes' (T2). The product_code column in T1 needs to reference code_id values where code_type="STREET" from T2. T2 primary key is based on two columns 'code_id' and 'code_type'.
The issue is t1 table has only one of the column from T2. i.e; product_code (T1) corresponds to code_id (T2) and code_type should always have value "STREET"
I am not getting how to implement the foreign key constraint on T1 in such scenario. Hope my explanation is clear. Feel free to ask for more clarifications. Please suggest.post CREATE TABLE statement for PRODUCTS & CODES tables -
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,
BjoernRollinHand 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" -
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!!!
MarioWelcome 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 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 -
SSAS 2008 Linking two cubes on the foreign key between two fact tables
Hi, all --
I have two cubes:
Cube 1 has Fact1 (F1, "Events") and 3 dimensions (D1, D2, D3)
Cube 2 has Fact2 (F2, "Sales") and 3 dimensions (D4, D1, D6)
As you can see, two cubes reuse D1 as their common dimension. In addition, F2 foreign keys into F1, e.g. F1 is "Events", and F2 is "Sales". Every "sale" is an "event", but not every "event" is
a "sale".
The question is, how to I link the two cubes and their two respective fact tables on the foreign key?
Thanks, Austin.Hi Austin,
According to your description, you want to retrieve data from two different cubes, right? In Analysis Services, to query multiple cubes from a single MDX statement you can use the LOOKUPCUBE function (you can't specify multiple cubes in your FROM statement).
The LOOKUPCUBE function will only work on cubes that utilize the same source database as the cube on which the MDX statement is running. For the detail information about it, please refer to the link below to see the blog.
Retrieving Data From Multiple Cubes in an MDX Query Using the Lookupcube Function
If I have anything misunderstood, please point it out.
Regards,
Charlie Liao
TechNet Community Support -
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 existI 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.. -
Multiple foreign key joins between two tables
Hi,
I have a question about building a repository.
I have a date dimension and one fact. The fact table has about 10 foreign key columns that link to the date Dimension.
In this case should I create 10 aliases to create joins in the Physical and BMM layer or is there any other way to handle this situation.
I am asking this question because 10 aliases can get very confusing for me at the later point of time while creating reports.
Using OBIEE 10.1.3Hi
I have a follow up question on this.
I am okay with not seeing the different date tables under the Subject area. Even if it just shows a it as a Simple DATE Dimension I am good with it.
In this case which is the efficient way, creating 10 aliases or creating 10 joins in the physical layer. I just figured out that we can create multiple joins between the same set of two tables but do not know how will that effect the way BI server works.
Please help me in understanding this concept.
thanks
This request id for OBIEE 10.1.3 -
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. -
Finding foreign keys of a child table,grandchild and all dependendents
Hi All,
I just came up with this sceanrio
I have to delete a record in a parent table with a condition provided will have to find all the child tables depends on it and should recursively find all the dependents of the child table.
How to achieve this.Please help with a query or guide.Thanks in advanceThanks visakh it gave me an idea and this script helped me
DECLARE @mytable VARCHAR(30) SET @mytable = 'test'
DECLARE @RecordID VARCHAR(8)
SET @RecordID = '00000001'
DECLARE @Order INT SET @Order = 0
DECLARE @Count INT
declare @tblname varchar(100),@query NVARCHAR(max)
if OBJECT_ID('tempdb..#OrderList','U') is not null
DROP TABLE #OrderList
CREATE TABLE #TEMP
OrderNo INT,
TableName VARCHAR(50)
CREATE TABLE #OrderList
RecordNo INT,
OrderNo INT,
TableName VARCHAR(50)
INSERT INTO #TEMP
VALUES ( @Order,
@mytable )
WHILE ( EXISTS(SELECT TableName
FROM #TEMP
WHERE OrderNo = @Order) )
BEGIN
SET @Order= @Order + 1;
INSERT INTO #TEMP
SELECT @Order,
t1.TABLE_NAME AS PointsFrom
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS r
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t1
ON t1.CONSTRAINT_NAME = r.CONSTRAINT_NAME
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS t2
ON t2.CONSTRAINT_NAME = r.UNIQUE_CONSTRAINT_NAME
WHERE t2.table_name IN (SELECT TableName
FROM #TEMP
WHERE OrderNo = ( @Order - 1 ))
END
INSERT INTO #OrderList
SELECT Row_number() OVER (ORDER BY OrderNo, TableName),
#TEMP.OrderNo,
#TEMP.TableName
FROM #TEMP
DROP TABLE #TEMP
--SELECT * FROM #OrderList
SET @Count = (SELECT Max(RecordNo)
FROM #OrderList)
WHILE (@Count <> 0 )
BEGIN
select @tblname = TableName FROM #OrderList WHERE RecordNo = @Count
select @query = 'DELETE from '+ @tblname
select @query
exec sp_executesql @query
SET @Count = @Count-1
END -
Binding for table produces list for other tables using foreign key and crea
Using
software Jdev 11G, WLS 11G, Oracle DB 11G, Windows Vista platform
technology EJB 3.0, jspx, backing beans, session bean
I cannot create a namedquery on my secondary table. The method for the column uses the entity object rather than the name and value of the column.
For instance,
(Coketruck) table has inventory records(Products) table
Coketruck has one to many to the Products table
Products has a many to one to the Coketruck
I need to return the products from the product table based on the CokeTruck but I cannot create a namedQuery because the method in the Product table is an entity object type instead of a long that I can use to look up all the products based off the column truck_id.
This is what I was expecting…
Private Long truckId;
public Long getTruckId() {
return truckId;
public void setTruckId (Long truckId) {
this. truckId = truckId;
Instead this is what I have…
@ManyToOne
@JoinColumn(name = "TRUCK_ID")
private Coketruck coketruck;
this. coketruck = coketruck
public Coketruck getCoketruck() {
return coketruck;
public void set Coketruck (Coketruck coketruck) {
this. coketruck = coketruck;
How do I do a query on the Product table to return all the products that are in the coketruck?
If I do the following it expects for me to pass the Entity Object which I cannot use as search criteria for my find method.
@NamedQuery(name = "Products.findById", query = "select o from Products o where o.truckId = :truckId")
On a different note but the same song…
I noticed that when I look at my Session Bean Data Contols that the coketruck already has a list of the products. I have created a jsp page with a backing bean and have been able to use the namedquery on the coketruck entity to retrieve the productList. Unfortunately I need to sort the products by type and was also not able to find where to perform the work to be able to iterate through the productList to get my desired display. Therefore I started looking at doing another namedquery that would only retrieve the product_type ordering by the truckId.
Seems I have come full circle… I don’t care what method I have to use to get the info back.
Any help is greatly appreciated!user9005175 wrote:
Hi!
I work on an application wich uses a shopping cart stored in a database. The shopping cart uses two tables:
CART: Holds information common for one shopping cart: the user it is connected to etc.
- Primary key: CART_ID
CART_ROW: One row in the cart, e.g. one new product to buy.
- Primary key: ROW_ID
- Foreign key: CART_ROW.CART_ID references CART.CART_ID
From the code the rows in the cart are collected per cart, as is modelled by the foreign key. There exists one more relationship, which we use in the code, but which is not modelled by a foreign key in the database. One row can be dependent on another row, which makes the other row a parent.
CART_ROW has a column PARENT_ID which references CART_ROW.ROW_ID.
Should we add a foreign key for PARENT_ID? Or are there any questions to consider when it is a foreign key to the same table?
I suggest to add foreign key it wont harm the performance (except while on insert when there would be validation for the foreign key). But it would prevent users to insert wrong/corrupt data either through code or directly by loggin in the database.
A while ago we added indexes, both on ROW_ID and on PARENT_ID. Could the index on PARENT_ID have been harmful, since there is no foreign key?
Index on parent_id would only be harmful if you do not make use of index after creating it (i.e. there is no query which make use of this index).
And if you decide to have a foreign key on parent_id then I suggest to have index too on parent_id as it would be helpful atleast when you delete any record in this table.
Best regards! -
Maintenance View for custom table with foreign key relationship
Hi Folks,
I have created a custom table with foreign key relationship with other check tables. I want to create a maintenance view / tablemaintenance generator. What all things I need to take care for the foreign keys related fields while creating the maintenance view / tablemaintenance generator.
Regards,
santoshHi,
You do not have to do anything explicitely for the foreign key relationships in the table maintainance generator.
Create the table maintainance generator via SE11 and it will take care of all teh foreign key checks by itself.
Regards,
Ankur Parab -
Basic doubt about Primary Key/Foreign Key in Oracle Tables
Hi,
I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle. Some of the people I know are telling me that Oracle does not encourage having Primary Keys/Foreign keys in its database tables.
However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. However I am being told that ETRM is not a reliable way of having correct information about table structure.
It would be great if any one of you provides me with some insight in this. Any pointers to a document would be great.
ThanksIt is not that PK/FKs are disallowed in Oracle Apps (there are some on the standard Oracle Apps tables), but they are typically not used. I am not positive what the logic behind this is, but my guess is that it was party due to the earlier versions of Oracle Apps pre-dating declarative database referential integrity in Oracle DB and also on performance issues with the standard referential integrity with the earlier versions of declarative database referential integrity.
As far as eTRM is concerned - I understood that the data is based on a design repository rather than a physical Oracle Apps DB. So all of the information in there is logically correct, but not necessarily enforced via the standard Oracle DB declarative referential integrity (rather by the application code or APIs).
Maybe you are looking for
-
How do I add multiple nics to set up a router wuth netcfg
Only all I get with multiple files is rnetlink answers file exists. I don't seem to be able to find much usefull information on the best way to do this to ue Arch as a router. (It was easy before)
-
Windows xp extended desktop not showing up on 2nd monitor all of a sudden
I've used a 2nd monitor as my main monitor for my T61. I powered down today to move to another location, when I reconnected to my usual 2nd monitor, the screen just comes up blue, the cursor jumps between my 2 monitors, but there is no Windows comin
-
Viewing pictures in N82 gallery
Hi, my N82 takes decent pictures, but viewing them is not fun at all, hopefully someone knows of a way to adjust the settings. Firstly when I take a photo with the phone held sideways(like a camera), and I go back to view them though gallery they hav
-
Hello i'm not great at dreamweaver, my background is more in print, I'm teaching my self dreamweaver. how do you change the colors of the buttons in spry content slide show?
-
JSTL sql tags with jndi datasource
Im trying to use JSTL sql tags but get "no suitable driver" when trying to connect to a jndi datasource. the jakarta dbtags works fine but jstl does not