Child table linked to what Parent?
Hello,
As I am learning db management, I am at a point where I am totally lost and I feel I am getting nowhere with Google. What I am doing is deleting a field from Table_A, it tells me ORA-02292: Integreity Constraint <random.table_B_FK2> violated - Child Record Found. Well I know peopl have this all the time, I am actually trying to figure out what command I can use to quickly tell me what the table is linked to so I can go delete the item there first. Below is what I am using to try to find the Parent table. Any help is greatly appreciated.
SQL> select table_name,constraint_name
2 from user_cons_columns where column_name=(
3 select a.COLUMN_NAME from user_cons_columns a,user_constraints b
4 where a.TABLE_NAME=b.TABLE_NAME
5 and b.constraint_type in ('P')
6 and a.TABLE_NAME='TABLE_A')
7 and constraint_name like '%FK%';
Dang, I should have been able to figure that one out. Thanks a lot though!!
I guess I am still not where I need to be with my above question. While the previous answer did give me what I thought I needed, I am now realizing that it is not it. I may be actually asking the question wrong.
So when I try to delete the item and get the error with the constraint, I decide to just search by the table name to get a list of the constraints bind to it. Below is what I used.
SQL> SELECT CONSTRAINT_NAME, R_CONSTRAINT_NAME FROM USER_CONSTRAINTS
2 WHERE TABLE_NAME= '<MYTABLEHERE>';
The results were no rows selected. So I then decided to verify my table was actually listed by doing the below.
SQL> SELECT TABLE_NAME FROM USER_CONSTRAINTS
From the results, my table was not listed yet I know the table exists because I can do the below and get results.
SQL> DESCRIBE <MYTABLEHERE>
Any thoughts?
Similar Messages
-
How to check that my table is parent table or child table before trucating
Hi:
say i wanted to trucate a table .the table might be a parent table or might be a child table.if its a child table then there wouldnt be any problems in truncating.
if its a parent table the i believe i would have to diable all the foreign key constraints from the child table referring to the parent table ..my question is
1. i have a table say ABC. before truncating how do i find out if table ABC is a parent table or not?
2.lets assume i tried to truncate the table ABC and i got the error saying that disable the foreign keys on the child table referring to the parent table ABC.
in my schema there are say 50 tables.out of which there might be 10 odd child tables referring to my parent table ABC.
so my question here would be how do i specifically find out these 10child tables referring to the Parent table ABC so that i can disable the foreign keys on the child tables.
Thanks 4 ur time in reading this and hopefully i think u wld give me a solution!!Hi,
Try this SQL below:
select r.owner, r.table_name
from user_constraints r, user_constraints o
where r.r_owner = o.owner and r.r_constraint_name = o.constraint_name
and o.constraint_type in ('P','U') and r.constraint_type = 'R'
and o.table_name = 'ABC';Cheers -
HI i have some questions which iam unclear please help me
1) in a parent child relationship.. is it always 1-m relation from parent to child?
2) can a parent table be on many side? i.e can a child - parent be 1- m?
3) if i itake employee as child table and department as parent table then dept_id will be the foreigh key in employee table ...
Now if i want to add a new employee who is not assigned to any department can i add it ?
4) In an identifying relationship ... a child table has concatenated primary key (pk of child,pk of parent)
should we still add any other primary key to the table....in addition to this concatenated key?
thanks in advance
rajHi!
1) in a parent child relationship.. is it always 1-m relation from parent to child?
yes unless you create a unique index on the foreign key column
2) can a parent table be on many side? i.e can a child - parent be 1- m?
no, if you need an n-m you will need an intersection table
e.g. employees - emp_dept - departments
in this case the emp_dept table would contain the foreign keys of employees and departments
3) if i itake employee as child table and department as parent table then dept_id will be the foreigh key in employee table ...
Now if i want to add a new employee who is not assigned to any department can i add it ?
no, you will have to insert the master first
Best regards,
PP -
How to find out child tables given a parent table /parent's constraint_nam
Hi
I need to disable a primary key but is not able to becoz of referential constraint
select child_constraint.table_name, child_constraint.constraint_name, child_detail.column_name
from user_cons_columns child_detail
join user_constraints child_constraint
on child_detail.constraint_name = child_detail.constraint_name
and child_detail.owner = child_detail.owner
and child_detail.table_name= child_detail.table_name
where child_constraint.constraint_type='R'
and child_constraint.status='ENABLED'
and child_constraint.r_constraint_name='SUBSCRIBER_PK';
and child_detail.table_name='ADDRESS_BOOK_GROUP';
Given a table name how would I know all the child tables and the child tables' columns referencing the parent keys?
thanksthanks for the reply
while the first query is correct
select child_constraints.table_name child_table_name, child_detail.constraint_name child_constraint_name
, child_detail.column_name child_column_name, child_constraints.constraint_type child_constraint_type
, child_constraints.status, parent_constraints.table_name parent_table_name, parent_detail.column_name parent_column_name
, parent_constraints.constraint_name parent_constraint_name
, parent_constraints.status parent_constraint_status from
user_cons_columns child_detail
join user_constraints child_constraints
on child_detail.constraint_name=child_constraints.constraint_name
and child_detail.owner=child_constraints.owner
and child_detail.table_name=child_constraints.table_name
join user_constraints parent_constraints
on parent_constraints.constraint_name=child_constraints.r_constraint_name
join user_cons_columns parent_detail
on parent_detail.constraint_name=parent_constraints.constraint_name
and parent_detail.owner=parent_constraints.owner
and parent_detail.table_name=parent_constraints.table_name
where
child_constraints.r_constraint_name in (
select constraint_name from user_constraints parent_constraint
where parent_constraint.constraint_type='P'
and parent_constraint.status='ENABLED'
and parent_constraint.table_name='SUBSCRIBER'
and child_constraints.constraint_type='R'
and parent_constraints.constraint_type='P'
--and child_constraints.status='ENABLED'
order by child_constraints.table_name
, child_detail.position
the second query return a lots of garbage why is this so?
select child_constraints.table_name child_table_name, child_detail.constraint_name child_constraint_name
, child_detail.column_name child_column_name, child_constraints.constraint_type child_constraint_type
, child_constraints.status, parent_constraints.table_name parent_table_name, parent_detail.column_name parent_column_name
, parent_constraints.constraint_name parent_constraint_name
, parent_constraints.status parent_constraint_status from
user_cons_columns child_detail
join user_constraints child_constraints
on child_detail.constraint_name=child_constraints.constraint_name
and child_detail.owner=child_constraints.owner
and child_detail.table_name=child_constraints.table_name
join user_constraints parent_constraints
on parent_constraints.constraint_name=child_constraints.r_constraint_name
join user_cons_columns parent_detail
on parent_detail.constraint_name=parent_constraints.constraint_name
and parent_detail.owner=parent_constraints.owner
and parent_detail.table_name=parent_constraints.table_name
where
child_constraints.constraint_type='R'
and parent_constraints.constraint_type='P'
--and child_constraints.status='ENABLED'
order by child_constraints.table_name
, child_detail.position
thanks -
I have a master table and i need to import the rows into the parent and child table.
Master table name is Flatfile_Inventory
Parent Table name is INVENTORY
Child Tables name are INVENTORY_AMOUNT,INVENTORY_DETAILS,INVENTORY_VEHICLE,
Error details will be goes to LOG_INVENTORY_ERROR
I have 4 duplicate rows in the Flatfile_Inventory which i have already inserted in the Parent and child table.
Again when i run the query using stored procedure,
its tells that all the 4 rows are duplicate and will move to the Log_Inventory_Error.
I need is if i have the duplicate rows in the flatfile_Inventory when i start inserting into the parent and child table the already inserted row have the unique ID i
must identify it and delete that row in the both parent and chlid table.And latest row must get inserted into the Parent and child table from Flatfile_Inventory.
Please help me to write the query i have attached the Full stored procedure Script..
Arunraj KumarHi Santhosh,
This is my Script.
-- =============================================
-- Stored Procedure for FLATFILE_INVENTORY
-- =============================================
-- Drop stored procedure if it already exists
DROP PROCEDURE SP_Flatfile_Inventory
GO
CREATE PROCEDURE SP_Flatfile_Inventory
AS
--USE IconicMarketing
GO
DECLARE
@FileType varchar(50) ,
@ACDealerID varchar(50) ,
@ClientDealerID varchar(50) ,
@DMSType varchar(50) ,
@StockNumber varchar(50) ,
@InventoryDate datetime ,
@StockType varchar(100) ,
@DMSStatus varchar(50) ,
@InvoicePrice numeric(18, 2) ,
@CostPack varchar(50) ,
@SalesCost numeric(18, 2) ,
@HoldbackAmount numeric(18, 2) ,
@ListPrice numeric(18, 2) ,
@MSRP varchar(max) ,
@LotLocation varchar(50) ,
@TagLine varchar(max) ,
@Certification varchar(max) ,
@CertificationNumber varchar(max) ,
@VehicleVIN varchar(50) ,
@VehicleYear bigint ,
@VehicleMake varchar(50) ,
@VehicleModel varchar(50) ,
@VehicleModelCode varchar(50) ,
@VehicleTrim varchar(50) ,
@VehicleSubTrimLevel varchar(max) ,
@Classification varchar(max) ,
@TypeCode varchar(100) ,
@VehicleMileage bigint ,
@EngineCylinderCount bigint ,
@TransmissionType varchar(50) ,
@VehicleExteriorColor varchar(50) ,
@VehicleInteriorColor varchar(50) ,
@CreatedDate datetime ,
@LastModifiedDate datetime ,
@ModifiedFlag varchar(max) ,
@InteriorColorCode varchar(50) ,
@ExteriorColorCode varchar(50) ,
@PackageCode varchar(50) ,
@CodedCost varchar(50) ,
@Air varchar(100) ,
@OrderType varchar(max) ,
@AgeDays bigint ,
@OutstandingRO varchar(50) ,
@DlrAccessoryRetail varchar(50) ,
@DlrAccessoryCost varchar(max) ,
@DlrAccessoryDesc varchar(max) ,
@ModelDesc varchar(50) ,
@Memo1 varchar(1000) ,
@Memo2 varchar(max) ,
@Weight varchar(max) ,
@FloorPlan numeric(18, 2) ,
@Purchaser varchar(max) ,
@PurchasedFrom varchar(max) ,
@InternetPrice varchar(50) ,
@InventoryAcctDollar numeric(18, 2) ,
@VehicleType varchar(50) ,
@DealerAccessoryCode varchar(50) ,
@AllInventoryAcctDollar numeric(18, 2) ,
@BestPrice varchar(50) ,
@InStock bigint ,
@AccountingMake varchar(50) ,
@GasDiesel varchar(max) ,
@BookValue varchar(10) ,
@FactoryAccessoryDescription varchar(max) ,
@TotalReturn varchar(10) ,
@TotalCost varchar(10) ,
@SS varchar(max) ,
@VehicleBody varchar(max) ,
@StandardEquipment varchar(max) ,
@Account varchar(max) ,
@CalculatedPrice varchar(10) ,
@OriginalCost varchar(10) ,
@AccessoryCore varchar(10) ,
@OtherDollar varchar(10) ,
@PrimaryBookValue varchar(10) ,
@AmountDue varchar(10) ,
@LicenseFee varchar(10) ,
@ICompany varchar(max) ,
@InvenAcct varchar(max) ,
@Field23 varchar(max) ,
@Field24 varchar(max) ,
@SalesCode varchar(max) ,
@BaseRetail varchar(10) ,
@BaseInvAmt varchar(10) ,
@CommPrice varchar(10) ,
@Price1 varchar(10) ,
@Price2 varchar(10) ,
@StickerPrice varchar(10) ,
@TotInvAmt varchar(10) ,
@OptRetail varchar(max) ,
@OptInvAmt varchar(10) ,
@OptCost varchar(10) ,
@Options varchar(max) ,
@Category varchar(max) ,
@Description varchar(max) ,
@Engine varchar(max) ,
@ModelType varchar(max) ,
@FTCode varchar(max) ,
@Wholesale varchar(max) ,
@Retail varchar(max) ,
@Draft varchar(max) ,
@Inventoryid int;
DECLARE Inventory_Cursor CURSOR FOR
SELECT * from [dbo].[FLATFILE_INVENTORY];
OPEN Inventory_Cursor
FETCH NEXT FROM Inventory_Cursor
INTO @FileType ,
@ACDealerID ,
@ClientDealerID ,
@DMSType ,
@StockNumber ,
@InventoryDate ,
@StockType ,
@DMSStatus ,
@InvoicePrice ,
@CostPack ,
@SalesCost ,
@HoldbackAmount ,
@ListPrice ,
@MSRP ,
@LotLocation ,
@TagLine ,
@Certification ,
@CertificationNumber ,
@VehicleVIN ,
@VehicleYear ,
@VehicleMake ,
@VehicleModel ,
@VehicleModelCode ,
@VehicleTrim ,
@VehicleSubTrimLevel ,
@Classification ,
@TypeCode ,
@VehicleMileage ,
@EngineCylinderCount ,
@TransmissionType ,
@VehicleExteriorColor ,
@VehicleInteriorColor ,
@CreatedDate ,
@LastModifiedDate ,
@ModifiedFlag ,
@InteriorColorCode ,
@ExteriorColorCode ,
@PackageCode ,
@CodedCost ,
@Air ,
@OrderType ,
@AgeDays ,
@OutstandingRO ,
@DlrAccessoryRetail ,
@DlrAccessoryCost ,
@DlrAccessoryDesc ,
@ModelDesc ,
@Memo1 ,
@Memo2 ,
@Weight ,
@FloorPlan ,
@Purchaser ,
@PurchasedFrom ,
@InternetPrice ,
@InventoryAcctDollar ,
@VehicleType ,
@DealerAccessoryCode ,
@AllInventoryAcctDollar ,
@BestPrice ,
@InStock ,
@AccountingMake ,
@GasDiesel ,
@BookValue ,
@FactoryAccessoryDescription ,
@TotalReturn ,
@TotalCost ,
@SS ,
@VehicleBody ,
@StandardEquipment ,
@Account ,
@CalculatedPrice ,
@OriginalCost ,
@AccessoryCore ,
@OtherDollar ,
@PrimaryBookValue ,
@AmountDue ,
@LicenseFee ,
@ICompany ,
@InvenAcct ,
@Field23 ,
@Field24 ,
@SalesCode ,
@BaseRetail ,
@BaseInvAmt ,
@CommPrice ,
@Price1 ,
@Price2 ,
@StickerPrice ,
@TotInvAmt ,
@OptRetail ,
@OptInvAmt ,
@OptCost ,
@Options ,
@Category ,
@Description ,
@Engine ,
@ModelType ,
@FTCode ,
@Wholesale ,
@Retail ,
@Draft ;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @VehicleVIN ;
-- ****************** insert into Inventory Table ***********
INSERT INTO INVENTORY
IconicDealerID,
StockNumber,
DMSType,
InventoryDate
VALUES (@ClientDealerID,@StockNumber,@DMSType,@InventoryDate);
set @Inventoryid = scope_identity();
PRINT @Inventoryid;
--Insert into Inventory_Details Table
INSERT INTO [INVENTORY_DETAILS]
InventoryID,
StockType,
DMSStatus,
LotLocation,
TagLine,
Certification,
CertificationNumber,
CreatedDate,
LastModifiedDate,
ModifiedFlag,
PackageCode,
OrderType,
AgeDays,
OutstandingRO,
Memo1,
Memo2,
Purchaser,
PurchasedFrom,
DealerAccessoryCode,
InStock,
AccountingMake,
SS,
Account,
AccessoryCore,
ICompany,
InvenAcct,
Field23,
Field24,
SalesCode,
Draft,
FTCode
VALUES (
@InventoryID,
@StockType,
@DMSStatus,
@LotLocation,
@TagLine,
@Certification,
@CertificationNumber,
@CreatedDate,
@LastModifiedDate,
@ModifiedFlag,
@PackageCode,
@OrderType,
@AgeDays,
@OutstandingRO,
@Memo1,
@Memo2,
@Purchaser,
@PurchasedFrom,
@DealerAccessoryCode,
@InStock,
@AccountingMake,
@SS,
@Account,
@AccessoryCore,
@ICompany,
@InvenAcct,
@Field23,
@Field24,
@SalesCode,
@Draft,
@FTCode
--Insert into Inventory_Amount Table
INSERT INTO [dbo].[INVENTORY_AMOUNT]
InventoryID,
AllInventoryAcctDollar,
OtherDollar,
PrimaryBookValue,
AmountDue,
LicenseFee,
CalculatedPrice,
OriginalCost,
BookValue,
TotalReturn,
TotalCost,
DlrAccessoryRetail,
DlrAccessoryCost,
DlrAccessoryDesc,
InternetPrice,
InventoryAcctDollar,
BestPrice,
Weight,
FloorPlan,
CodedCost,
InvoicePrice,
CostPack,
SalesCost,
HoldbackAmount,
ListPrice,
MSRP,
BaseRetail,
BaseInvAmt,
CommPrice,
Price1,
Price2,
StickerPrice,
TotInvAmt,
OptRetail,
OptInvAmt,
OptCost,
Wholesale,
Retail
VALUES (
@InventoryID,
@AllInventoryAcctDollar,
@OtherDollar,
@PrimaryBookValue,
@AmountDue,
@LicenseFee,
@CalculatedPrice,
@OriginalCost,
@BookValue,
@TotalReturn,
@TotalCost,
@DlrAccessoryRetail,
@DlrAccessoryCost,
@DlrAccessoryDesc,
@InternetPrice,
@InventoryAcctDollar,
@BestPrice,
@Weight,
@FloorPlan,
@CodedCost,
@InvoicePrice,
@CostPack,
@SalesCost,
@HoldbackAmount,
@ListPrice,
@MSRP,
@BaseRetail,
@BaseInvAmt,
@CommPrice,
@Price1,
@Price2,
@StickerPrice,
@TotInvAmt,
@OptRetail,
@OptInvAmt,
@OptCost,
@Wholesale,
@Retail
--Insert into Inventory_Vehicle Table
INSERT INTO [dbo].[INVENTORY_VEHICLE]
InventoryID,
InteriorColorCode,
ExteriorColorCode,
Air,
ModelDesc,
VehicleType,
VehicleVIN,
VehicleYear,
VehicleMake,
VehicleModel,
VehicleModelCode,
VehicleTrim,
VehicleSubTrimLevel,
Classification,
TypeCode,
VehicleMileage
VALUES (
@InventoryID,
@InteriorColorCode,
@ExteriorColorCode,
@Air,
@ModelDesc,
@VehicleType,
@VehicleVIN,
@VehicleYear,
@VehicleMake,
@VehicleModel,
@VehicleModelCode,
@VehicleTrim,
@VehicleSubTrimLevel,
@Classification,
@TypeCode,
@VehicleMileage
-- Move cursor to Next record
FETCH NEXT FROM Inventory_Cursor
INTO @FileType ,
@ACDealerID ,
@ClientDealerID ,
@DMSType ,
@StockNumber ,
@InventoryDate ,
@StockType ,
@DMSStatus ,
@InvoicePrice ,
@CostPack ,
@SalesCost ,
@HoldbackAmount ,
@ListPrice ,
@MSRP ,
@LotLocation ,
@TagLine ,
@Certification ,
@CertificationNumber ,
@VehicleVIN ,
@VehicleYear ,
@VehicleMake ,
@VehicleModel ,
@VehicleModelCode ,
@VehicleTrim ,
@VehicleSubTrimLevel ,
@Classification ,
@TypeCode ,
@VehicleMileage ,
@EngineCylinderCount ,
@TransmissionType ,
@VehicleExteriorColor ,
@VehicleInteriorColor ,
@CreatedDate ,
@LastModifiedDate ,
@ModifiedFlag ,
@InteriorColorCode ,
@ExteriorColorCode ,
@PackageCode ,
@CodedCost ,
@Air ,
@OrderType ,
@AgeDays ,
@OutstandingRO ,
@DlrAccessoryRetail ,
@DlrAccessoryCost ,
@DlrAccessoryDesc ,
@ModelDesc ,
@Memo1 ,
@Memo2 ,
@Weight ,
@FloorPlan ,
@Purchaser ,
@PurchasedFrom ,
@InternetPrice ,
@InventoryAcctDollar ,
@VehicleType ,
@DealerAccessoryCode ,
@AllInventoryAcctDollar ,
@BestPrice ,
@InStock ,
@AccountingMake ,
@GasDiesel ,
@BookValue ,
@FactoryAccessoryDescription ,
@TotalReturn ,
@TotalCost ,
@SS ,
@VehicleBody ,
@StandardEquipment ,
@Account ,
@CalculatedPrice ,
@OriginalCost ,
@AccessoryCore ,
@OtherDollar ,
@PrimaryBookValue ,
@AmountDue ,
@LicenseFee ,
@ICompany ,
@InvenAcct ,
@Field23 ,
@Field24 ,
@SalesCode ,
@BaseRetail ,
@BaseInvAmt ,
@CommPrice ,
@Price1 ,
@Price2 ,
@StickerPrice ,
@TotInvAmt ,
@OptRetail ,
@OptInvAmt ,
@OptCost ,
@Options ,
@Category ,
@Description ,
@Engine ,
@ModelType ,
@FTCode ,
@Wholesale ,
@Retail ,
@Draft ;
END
CLOSE Inventory_Cursor;
DEALLOCATE Inventory_Cursor;
GO
SET ANSI_PADDING OFF
GO
Arunraj Kumar -
Hi all,
Long time ago, I manually created a Database (APGriMMRP) and 3 Tables (dbo.Table_1_XYcoordinates, dbo.Table_2_Soil, and dbo.Table_3_Water) in my SQL Server 2012 Management Studio (SSMS2012). The dbo.Table_1_XYcoordinates has the following columns: file_id,
Pt_ID, X, Y, Z, sample_id, Boring. The dbo.Table_2_Soil has the following columns: Boring, sample_date, sample_id, Unit, Arsenic, Chromium, Lead. The dbo.Table_3_Water has the following columns: Boring, sample_date, sample_id, Unit, Benzene, Ethylbenzene,
Pyrene. The dbo.Table_1_XYcoordinates is a Parent Table. The dbo.Table_2_Soil and the dbo.Table_3_Water are 2 Child Tables. The sample_id is key link for the relationship between the Parent Table and the Child Tables.
Problem #1) How can I print out or export these 3 dbo Tables?
Problem #2) If I right-click on the dbo Table, I see "Start PowerShell" and click on it. I get the following error messages: Warning: Failed to load the 'SQLAS' extension: An exception occurred in SMO while trying to manage a service.
--> Failed to retrieve data for this request. --> Invalid class. Warning: Could not obtain SQL Server Service information. An attemp to connect to WMI on 'NAB-WK-02657306' failed with the following error: An exception occurred in SMO while trying
to manage a service. --> Failed to retrieve data for this request. --> Invalid class. .... PS SQLSERVER:\SQL\NAB-WK-02657306\SQLEXPRESS\Databases\APGriMMRP\Table_1_XYcoordinates> What causes this set of error messages? How can
I get this problem fixed in my PC that is an end user of the Windows 7 LAN System? Note: I don't have the regular version of Microsoft Visual Studio 2012 in my PC. I just have the Microsoft 2012 Shell (Integrated) program in my PC.
Problem #3: I plan to create an XML Schema Collection in the "APGriMMRP" database for the Parent Table and the Child Tables. How can I handle the relationship between the Parent Table and the Child Table in the XML Schema Collection?
Problem #4: I plan to extract some results/data from the Parent Table and the Child Table by using XQuery. What kind of JOIN (Left or Right JOIN) should I use in the XQuerying?
Please kindly help, answer my questions, and advise me how to resolve these 4 problems.
Thanks in advance,
Scott ChangIn the future, I would recommend you to post your questions one by one, and to the appropriate forum. Of your questions it is really only #3 that fits into this forum. (And that is the one I will not answer, because I have worked very little with XSD.)
1) Not sure what you mean with "print" or "export", but when you right-click a database, you can select Tasks from the context menu and in this submenu you find "Export data".
2) I don't know why you get that error, but any particular reason you want to run PowerShell?
4) If you have tables, you query them with SQL, not XQuery. XQuery is when you query XML documents, but left and right joins are SQL things. There are no joins in XQuery.
As for left/right join, notice that these two are equivalent:
SELECT ...
FROM a LEFT JOIN b ON a.col = b.col
SELECT ...
FROM b RIGHT JOIN a ON a.col = b.col
But please never use RIGHT JOIN - it gives me a headache!
There is nothing that says that you should use any of the other. In fact, if you are returning rows from parent and child, I would expect an inner join, unless you want to cater for parents without children.
Here is an example where you can study the different join types and how they behave:
CREATE TABLE apple (a int NOT NULL PRIMARY KEY,
b varchar(23) NOT NULL)
INSERT apple(a, b)
VALUES(1, 'Granny Smith'),
(2, 'Gloster'),
(4, 'Ingrid-Marie'),
(5, 'Milenga')
CREATE TABLE orange(c int NOT NULL PRIMARY KEY,
d varchar(23) NOT NULL)
INSERT orange(c, d)
VALUES(1, 'Agent'),
(3, 'Netherlands'),
(4, 'Revolution')
SELECT a, b, c, d
FROM apple
CROSS JOIN orange
SELECT a, b, c, d
FROM apple
INNER JOIN orange ON apple.a = orange.c
SELECT a, b, c, d
FROM apple
LEFT OUTER JOIN orange ON apple.a = orange.c
SELECT a, b, c, d
FROM apple
RIGHT OUTER JOIN orange ON apple.a = orange.c
SELECT a, b, c, d
FROM apple
FULL OUTER JOIN orange ON apple.a = orange.c
go
DROP TABLE apple, orange
Erland Sommarskog, SQL Server MVP, [email protected] -
Insert Record with Parent/Child Tables doesn't work with Oracle - unlike AC
Hi,
I just Migrated a MS Access 2010 Database to an Oracle 11g Backend with the SQL Developer Tool.
The Migration went fine, all the Tables and Views are migrated.
I'm working with MS Access as Frontend.
The application has some Datasheets with Subdatasheets with Parent/Child Relationship. (1-n Relationship)
After changing to Oracle, it's not possible, to Insert a new Record in a Subdatasheet I always get the following Error Message:
"The Microsoft Access database engine cannot find a record in the table 'xxxx' with key matching field(s) 'zzzzz'"
It used to work perfect with the MS Access Backend, do I need a trigger which first adds the child Record ?
Or what should I do?
Thank youHi Klaus,
Thanks for your answer. I still haven't solved my problem. The only way would be to use a singel 1:n Relationship, but in fact I need a n:m Relationship.
I tried the same scenario with a new Access Application, same result.
To clearify my problem.
Goal: Parent Form with Parent Records, Linked Child Form with Child Records in a Datasheet View => Insert of a NEW Child Record.
I have 3 Tables (table1 = Parent tabel, table2 = Child Table, table12 = n:m Tabel with PK and two FK)
The Recordsource of the Parent Form is Tabel1
The Recordsource of the Child Form is Table2 joined with Table12.
In my Old Access Project, Access Triggered the Insert and filled Table12 with the NEW PK of Table2.
It seems like Access can't do that anymore....
I'm pretty desperate and I'm sure it is just a litte thing to fix..... -
SHOW THE PARENT CHILD TABLE RELATIONSHIP TABLE
hi experts,
I want show the parent child relation ship tables
for exmple iam passing the emp table then display related child tables like dept,grade after that again child table(dept,grade) related to child relationship tables like recursive
Regards,
VENKATProbably something like below. This may not be exactly what you are looking for, but one way to get what you are asking for.
Only if you can give specifics, of your Input being passed and the Output, it might be possible to provide more help. But you also need to help us with your best effort on this.
select *
from (
select prior table_name Child, table_name Parent
from user_constraints
start with constraint_name = some_constraint_name_of_Parent_Table
connect by constraint_name = prior r_constraint_name
) a
where a.child is not null; -
Update column data to Upper Case in parent and child table
Hi ,
I am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
when updating parent row:
ORA-02292: integrity constraint (XXXXXXXXXXXXXX_FK) violated - child record found
When updatng corresponding child row:
ORA-02291: integrity constraint (XXXXXXXXXXXXXXXX_FK) violated - parent key not found
how can i update on both the places ?
Regards,
AAI am facing issue while updating column value to upper case in parent table and child table. How can i do that ?
Why do you need to do that?
That is just ONE of several questions you should answer before you start modifying your data.
1. What is your 4 digit Oracle version? (result of SELECT * FROM V$VERSION)
2. If both values are the same case what difference does it make what that case is?hen you don't need to alter your original data.
3. What is the source of the column values you are using now? If you change your data to upper case it will no longer be identical to the source data.
4. What is your plan for enforcing future values to be stored in UPPER case? Are you going to use a trigger? Have you written and tested such a trigger to see if it will even work the way you expect?
5. Why aren't you using a surrogate key instead of a 'business' data item? You have just demonstrated one reason why surrogate keys can be useful: their actual value is NOT important.
You should reexamine your problem and architecture and consider other alternatives.
One alternative is to add a new 'surrogate key' column to use as the primary key. Just create a new sequence and use a trigger to populate the new column. Your current plans will require a trigger to perform the case conversion so instead of the just use the trigger to provide the value.
If the change is being done to facilitate searching you could just add a VIRTUAL column UPPER_MY_COLUMN and index that instead. Then you could search on that new virtual column and the data values would still be identical to the original data source. -
Parent - child table issue wrt to count - SQL question
I have a scenario:
There are 2 tables (parent and child). lets say, case summary table and task level dimension table.
for every case id in case summary table, there would be multiple tasks in task level dim table with a flag indicator set to 1 for all tasks.
but while counting the number of cases active with flag indicator 1 (ofcourse when joining case summary table with task dimension table), for a case id only 1 instance of task needs to be accounted (even though it has more than one task , for counting active cases, the flag ind corresponding to a task in a case if set to 1 , then the case is considered active)..but while joining and taking count of case ids with flag indicator as 1, you get the count of every task row of a case which is incorrect logically. how to discard the rest of child records of a case in child table (task dimension table)?
I am not sure how to achieve this in sql query
Kindly help!
Case summary table
case id, busininess_unit, agent_name
1001, admin, Ram
1002, Finance, Sam
task table
case id, task_id,task_name, flag_indicator
1001, 1, 'New', 1
1001,2, 'Open',1
1001,3,'In progress',1
1002, 4, 'New', 1
(In fact task_id is not a big deal... even you can assume task id doesn't exist..only task name ... )
now my question... if my query should get the current active cases (ind=1); as per above it should essentially give 2... but my query gives me 4..you know the reason why.. but how do i get the correct count?
Thanks!may be you need just this:
select count(distinct case_id) from task
where indicator = 1;
If this is not what you are looking for, please elaborate and tell us the expected output and rest of the details as mentioned in FAQ Re: 2. How do I ask a question on the forums?: -
Parent child tables - how to maintain RI
Here is my scenario:
In our model, we have parent child relationship between tables.
We are not sure how the parent tables are populated. If incremental update, it should be fine (assuming if needed rows will be inserted in the child table manually). If the tables are truncated and data is inserted again – that might be a problem since there exist relationship with child tables. What are the various options for handling such cases?
Option1: cascade delete
Option 2: ...?I'm not sure I understand the goal here...
- Are you trying to design a data model? If so, wouldn't the business and data requirements tell you whether you need to truncate and reload the parent table or whether you can do an incremental load? It wouldn't seem to make sense to design a data model with no understanding of how the model is going to be used.
- Are you trying to design a load process that works with an existing data model? If so, are you trying to design an incremental load? Or a load that involves a truncate and reload? Does the existing data model have foreign key constraints?
Specifying the Oracle version and a bit of information about the application (i.e. is this an OLTP application, a data warehouse, something else) would probably also be helpful.
Justin -
DB Adapter wizard – WHERE clause on parent and child tables not working.
I have two tables, SECURITY and SECURITY_POSITIONS, where SECURITY has a 1:M relationship with SECURITY_POSITIONS. I used the DB-adapter wizard to create the relationship and the following WHERE clause expression which is looking at both the parent and the child tables;
The expression builder looks like this:
AND
|--- 1. partitionKey EQUAL p_SearchKey
|--- 2. securityType EQUAL “DBT”
|--- 3. securityPositionsCollection.dealReference EQUAL “NA”
The primary key on SECURITY = PARTITION_KEY and SECURITY_REFERENCE
The foreign key from SECURITY_POSITIONS to SECURITY = PARTITION_KEY and SECURITY_REFERENCE
securityType is on SECURITY table (master)
securityPositionsCollection.dealReference is on SECURITY_POSITIONS table (child)
The invoke on the database adapter is selecting a row in securityPositionsCollection for each child row, rather than just those with dealReference = “NA”!
I turned on DEBUG logging in the BPEL console and I can see that there are 2 SELECT queries run (guess this is how Toplink does it!), where the 1st query appears to select the parent rows and the 2nd query selects the child rows.
However the 2nd query is not working because it is failing to select only those child rows where dealReference = “NA”. Also, don’t know why the 2nd SELECT query needs to specify the child SECURITY_POSITIONS table twice in the FROM clause, because that seems to be causing the problem.
1st query executed is as follows;
SELECT DISTINCT t0.PARTITION_KEY, t0.SECURITY_REFERENCE, t0.SECURITY_TYPE
FROM CENTRAL.SECURITY t0, CENTRAL.SECURITY_POSITIONS t1
WHERE ((((t0.PARTITION_KEY = ?) AND (t0.SECURITY_TYPE = ?)) AND (t1.DEAL_REFERENCE = ?)) AND ((t1.SECURITY_REFERENCE = t0.SECURITY_REFERENCE) AND (t1.PARTIT
ION_KEY = t0.PARTITION_KEY)))
bind => [200706200000, DBT, NA]
2nd query executed is as follows, where child table appears twice! ;
SELECT DISTINCT t0.DEAL_REFERENCE, t0.PARTITION_KEY, t0.SECURITY_REFERENCE
FROM CENTRAL.SECURITY_POSITIONS t0,
CENTRAL.SECURITY_POSITIONS t2,
CENTRAL.SECURITY t1
WHERE ((((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND (t0.PARTITION_KEY = t1.PARTITION_KEY)) AND
(((t1.PARTITION_KEY = ?) AND (t1.SECURITY_TYPE = ?)) AND
(t2.DEAL_REFERENCE = ?))) AND
((t2.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND
(t2.PARTITION_KEY = t1.PARTITION_KEY)))
bind => [200706200000, DBT, NA]
Anyone experienced the same problem e.g. why is toplink making the query more complicated that it needs to be, because the query only needs to reference the SECURITY_POSITIONS table once, as follows;
SELECT DISTINCT t0.DEAL_REFERENCE, t0.PARTITION_KEY, t0.SECURITY_REFERENCE
FROM CENTRAL.SECURITY_POSITIONS t0,
CENTRAL.SECURITY t1
WHERE ((((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND (t0.PARTITION_KEY = t1.PARTITION_KEY)) AND
(((t1.PARTITION_KEY = '200706200000') AND (t1.SECURITY_TYPE = 'DBT')) AND
(t0.DEAL_REFERENCE = 'NA'))) AND
((t0.SECURITY_REFERENCE = t1.SECURITY_REFERENCE) AND
(t0.PARTITION_KEY = t1.PARTITION_KEY)))Hello,
It looks like you have configured your 1:M relationship to use batch reading. This causes the query to bring in the Security_Position table's objects to use the same selection criteria as was used on the initial query, with a join statement. This is more efficient in most cases as it ensures only the Security_positions needed for the Security objects to be fully built are read, in a single query.
The selection criteria added is only used to filter out the Security objects. All referenced Security_Positions must be read in for the returned Security objects so that the data matches what is in the database. If you do not want the Security_Positions, you might try using indirection on the mapping which will delay the second query until you need the Security_Positions. Or, if you want only the Security_Positions with dealReference EQUAL “NA", you could do a query specifically to filter on them.
Best Regards,
Chris -
In the parent table has a ROWID of an index of the child table FK!
From the structure of the heap table is a problem.
PK has a parent table.
Child table has a FK.
If you have FK to the parent table has a ROWID, I think in terms of speed to get the best performance.
what do you think?
Edited by: user5647868 on 2011. 9. 29 오후 10:46Of course, if the parent table FK ribildeuhal should rebuild the index.
In reality, however, if the parent table, there were no ribildeuhaneun.
If you need to rebuild a lot if you have a DOWNTIME.
In some cases, even given the option to ALTER TABLE will be.
Is the child table FK halgeot rebuild?
FK using ROWID in the index of the parent decide to disable?
And so on. -
Update data to upper case in parent/child tables
Hi Gurus!
In production we have a product table and which is being reference by many tables making it parent child relationship. By mistake, we realized that last month some product were added in lower case and now we got a request to update all these product codes to upper case so that the existing code that use these tables have no impact. Appreciate if you can give some idea on how can I update the existing data in the parent table to upper case along with the child records?
Regards
SriAre the product code that you need to update what is stored in the child tables? If so, then you would need to do it in several steps, something like:
Identify the child tables
SELECT table_name, constraint_name
FROM user_constraints
WHERE r_constraint_name = (SELECT constraint_name
FROM user_constraints
WHERE table_name = 'PRODUCT_TABLE' and
constraint_type = 'P');Create the new upper case product code in product table:
INSERT INTO product_table
SELECT UPPER(product_code), other_columns
FROM product_table
WHERE product_code <> UPPER(product_code);Update the child tables to uppercase the product codes
UPDATE child1
SET product_code = UPPER(product_code)
WHERE product_code <> UPPER(product_code);finally, delete the lower case product codes from product_table
DELETE FROM product_table
WHERE product_code <> UPPER(product_code);John -
How can we archive Partioning in parent child tables in Normalised way.
Hi Friends.
Could you please suggest me
How can we archive Partioning in parent child tables in Normalised way.
Bill_parent(
Bill_no number,
Bill_date date .-- I want to create Partition on this column
customer_id
Bill_Child{
bill_no number,
Bill_c_no number,
Item_code number
Qty number
Bill_Acsry{
Bill_c_no number,
acsry_it_code number,
qty number
Now for there Child Table I have also create a Bill_date column that is against Normalization
i.e
Bill_parent(
Bill_no number,
Bill_date date.
customer_id
) Partion by Range (Bill_date).......................
Bill_Child{
bill_no number,
Bill_c_no number,
Item_code number
Qty number,
Bill_Date date,-- against normalisation
}Partion by Range (Bill_date).......................
Bill_Acsry{
Bill_c_no number,
acsry_it_code number,
qty number,
Bill_Date date,-- against normalisation
}Partion by Range (Bill_date)....
with regards
Siddharth Singh([email protected])Looks like the new Reference Partitioning feature in 11g is what you want. In previous versions I think you're stuck with the denormalisation.
Maybe you are looking for
-
How to configure Spring Data JPA to handle sdo_geometry and Timestamp(0)?
Hi all, I'm new to this community, not sure if I'm posting in the right place. I'm an Oracle old-hand, but new to Spring Data, having done a bit on postGIS, but now trying to apply it to Oracle. My problem: I have a new maven project, with Entity an
-
Can't be iMessages.. Maybe... Sort of...
So I've had several iPhones and recently purchased and iPhone Six and moved from O2 to vodafone. My pac code experienced serious problems being moved but that has appeared To be resolved. However tonight I noticed that my partner (who has an iPhone 5
-
Interactive widget goes full screen but Review widget does not...
Anyone know why this is or if there is any way to make it go full screen? Thanks
-
Date Rules - Date Management (CRM-BF-DAT) - SAP Library
To add a comment, please log in or register on the top of this page and choose Reply. Please write your comment in English. You can also go back to the SAP help page.
-
Can I use iMovie app on imported videos? It doesn't specify
Does anyone know if I can use the iMovie app to edit videos that I have imported from my camera, can't seem to find any info on this