Home » SQL & PL/SQL » SQL & PL/SQL » SQL coding
SQL coding [message #229914] Tue, 10 April 2007 05:30 Go to next message
siva27
Messages: 34
Registered: April 2007
Location: Chennai
Member

Ex:
I have to tables TABLE-A, TABLE-B

CREATE TABLE A(HEADER_ID NUMBER(4) PRIMARY KEY,BROKER_CODE VARCHAR2(10),E_DATE DATE,AGENT VARCHAR2(10))

CREATE TABLE B(LINE_ID NUMBER(4) PRIMARY KEY,HEADER_ID NUMBER REFERENCES XX_JVG_HEADER(HEADER_ID),INVOICE_NO NUMBER(4),LOT_NO NUMBER(4))

1) I will insert the data manually raaa.I'm taking HEADER_ID as a Primary Key in Table-A & Foriegn Key in Table-B.
2) Again i have taken LINE_ID as a Primary Key in Table-B .If i try to insert the data into Table-B the HEADER_ID automatically should enter in Table-B.
3) But the HEADER_ID should be the same for Table-A & Table-B.

Table-A
2,'abc','12-mar-2002','chennai'

Table-B
1,2,1,1

Header_id should be same in 2 tables i.e -- 2
we have to create triggers or any...pls let me know ASAP.

If any one is having the coding u can pls send me to siva_gonuguntla@yahoo.com


Thanks,
Sivaprasad G
Re: SQL coding [message #230000 is a reply to message #229914] Tue, 10 April 2007 09:01 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
I'm obviously missing something - in the sample data you have provided, the HEADER_ID's ARE the same in both tables.

If you want to ensure that the header id in Table_B always amtches a header_Id in table_A, then just create a foriegn key constraint from table_b.header_id to table_a.header_id (as it looks like you have done).

If I'm missing the point, could you provide some extra explanation?
Re: SQL coding [message #230133 is a reply to message #230000] Wed, 11 April 2007 00:33 Go to previous messageGo to next message
siva27
Messages: 34
Registered: April 2007
Location: Chennai
Member

HI,

Assume that there r 2tables.One is the Master,2nd is the Detail table.
I will enter only master details,later i have to enter the details data also thn i need the Header_id show be the same.

I have taken as a Primary Key n Foriegn Key relation.
Whn i'm inserting the data in the Detail table automatically the Header_id as to be the same as in the Table-A.

If u have the code pls send to my mail id :siva_gonuguntla@yahoo.com


Regards
Siva
Re: SQL coding [message #230155 is a reply to message #230133] Wed, 11 April 2007 01:43 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Siva:
  1. OraFAQ is a public forum, ask questions here and get replies here. If you want private sessions, hire a consultant.
  2. Use proper language. Don't cut corners by omitting vowels. It is unprofessional. English is not my mother tongue either but words like "pls", "tht" don't exist. Let alone that "r" is a proper verb.


MHE

[Updated on: Wed, 11 April 2007 01:43]

Report message to a moderator

Re: SQL coding [message #230249 is a reply to message #230133] Wed, 11 April 2007 05:18 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
And what happens if someone else has also entered a header_id in the meantime - how is the code supposed to decide which header record to join the detail records on to?

Previous Topic: Compiling in native and have FOR statment return compiled with errors
Next Topic: Hi guys please help me in removing this bug....
Goto Forum:
  


Current Time: Mon Dec 05 09:18:19 CST 2016

Total time taken to generate the page: 0.10824 seconds