Please, I have the following question on the foreign key and the ora-00904

Thanks in advance!

I created the table:

Create the Department table
(
DNAME varchar (15) NOT NULL,
deptID number (5) NOT NULL,
Primary key (dname, deptid)
)

then...

Create table Manager
(
MgrID number (10) not null,
Not null, name varchar (10)
Start_date date not null,
Primary key (mgrid),

CONSTRAINT fk_department
FOREIGN KEY (dname, deptip)
Department of REFERENCES (dname, deptid)
)

Trying to create the table with the constraint, it yeilds one:

ORA-00904: "DNAME": invalid identifier
+.. .with an asterisk under "dname" in line: FOREIGN KEY (dname, deptip) +.

I tried joining my name of the column with quotation marks ("" "); capitalized for consistency; and we tried creating and editing then - all to nothing will do. I also tried to use the user interface with Oracle Express Edition and the moment where I click on create, the same error appears. Could someone help please straighten out me up - was this threat for four days.

Thanks again!

Hello

Welcome to the forum!

Columns that will reference the other table must be declared just like all the other columns; including the names in a FOREIGN KEY constraint is not auotmatically define them.
It works:

CREATE TABLE Manager
(       mgrid          NUMBER (10)     NOT NULL,
     Name          VARCHAR (10)     NOT NULL,
     Start_date      DATE          NOT NULL,
     dname          VARCHAR2 (15),               -- New
     deptid          NUMBER (5),               -- New
PRIMARY KEY (mgrid),
     --
CONSTRAINT fk_department
FOREIGN KEY           (dname, deptid)
REFERENCES department (dname, deptid)
);

(assuming that the departments table, you posted, there).

Is there a reason why you use VARCHAR instead of VARCHAR2?

In the departments table, do you really need both dname and deptid in the primary key? For example, if you have a line with name = "ACCOUNTING" and deptid = 10; is it possible that you could have another line with deptid = 10 and some different dname, say 'REASEARCH '? It is more common to only have a deptid as primary key and have columns in the foreign key constraints that reference.

Tags: Database

Similar Questions

  • With the help of the ORA-00904 granted by ROLE

    Hi all

    I have an error using the grant through ROLE (Oracle 11.2.0.1 on redhat Linux)

    Here is the explanation of my problem:

    I create a package to wear patterns

    create or replace 
    PACKAGE                     usera.pkg_utils AS 
     function f_my_function return RAW;
    END pkg_utils;
    

    I create the package body:

    create or replace 
    PACKAGE BODY usera.pkg_utils  AS 
     function f_my_function return RAW  is
      v_uuid RAW(16);
    begin
      v_uuid := sys.dbms_crypto.randombytes(16);
      return (utl_raw.overlay(utl_raw.bit_or(utl_raw.bit_and(utl_raw.substr(v_uuid, 7, 1), '0F'), '40'), v_uuid, 7));
    end f_random_uuid;
    END pkg_utils;
    

    I create a 'R_ROLE1' role to which I admit "EXECUTE ON USERA. PKG_UTILS TO R_ROLE1.

    I give you that R_ROLE1 to the PUBLIC so that each user can access the package USERA. PKG_UTIS

    If I call another user f_my_function, it works well.

    If I call another user from a procedure f_my_function I get "ORA-00904".

    ex: to UserB

    create or replace 
    PROCEDURE P_PROC
    AS
    num int;
    uuid_ RAW(16);
    BEGIN
        select usera.pkg_utils.f_my_function() into uuid_ from dual;
    END P_PROC;
    /
    

    If I give you that directly "GRANT EXECUTE ON USERA. PKG_UTILS TO PUBLIC' so it works well.

    Thus, the error comes from the fact that I use a role, but I can't fix it. I don't understand why USERB does not use its grant to the role of r_role1 granted to PUBLIC.

    Is there something as USERB is unusable cascade role during the call to a procedure? is there something to "activate"? ".

    Thank you all

    See the doc database security for your answer and the explanation of what others have said.

    http://docs.Oracle.com/CD/B28359_01/network.111/B28531/authorization.htm#i1007304

    Operation of the roles in PL/SQL blocks

    The use of roles in a PL/SQL block depends on if it is an anonymous block, or a block named (stored procedure, function, or trigger), and if it runs with the rights of the author or the rights of the applicant.

    Roles used in the appointed with rights to define blocks

    All roles are disabled in any PL/SQL block named (stored procedure, function, or trigger) that runs with the rights of the author. Roles are not used to privilege control, and you cannot define roles within the procedure of a DEFINER rights.

    The SESSION_ROLES view shows all roles that are currently enabled. If a named PL/SQL block that runs with Definer Rights queries SESSION_ROLES , then the query will return no rows.

  • How to set the condition of rule to check the Primary Key, Foreign Key and Unique

    I use Oracle 10.2
    Could someone tell me please how to set the rule condition to check the primary key, foreign key constraint of uniqueness?

    Hello

    Primary key, unique constraints and foreign key are better applied using the native functionality of database constraint. If you like the rules to check if a key exists at the time of the evaluation, you can use a function defined by the user in a rule condition and this function can ask to turn the table keys.

    Hope this helps,
    -Aravind.

  • I have Windows 7 ultimate 64 bit product key and I can't activate this code error 0xC004E003

    It has been activated in my laptop but I wanted to expand my C volume, so I formatted C to do a clean install and now it cannot be activated so what can I do now to solve this problem?

    Have you tried to restart by phone?

    How to activate Windows 7 manually (activate by phone)
     
    1) click Start and in the search for box type: slui.exe 4
     
    (2) press the ENTER"" key.
     
    (3) select your "country" in the list.
     
    (4) choose the option "activate phone".
     
    (5) stay on the phone (do not select/press all options) and wait for a person to help you with the activation.
     
    (6) explain your problem clearly to the support person.
     
    http://support.Microsoft.com/kb/950929/en-us

    Is it an upgrade license?

    However, the requirements for the media upgrade is that you have an operating system already eligible such as Windows XP or Vista installed to use it. Since the Windows 7 end user license agreement.

    15 UPDATES. To use upgrade software, you must first be licensed for the software that is eligible for the upgrade. After the upgrade, this agreement takes the place of the agreement for the software that you upgraded. After upgrade, you can no longer use the software that you upgraded.

    So, if you are always denied, you will just have to reinstall Windows XP or Vista and let it do the verification of eligibility.

  • I have the problem with connecting new gen 3 ATV to my wifi network.  This device must be used for the TV on the floor.  I have a GEN 3 oldest device installed in TV downstairs. I followed the instructions but does not connect.

    I just bought new gen 3 ATV.  Must be installed in the TV upstairs.   Unable to connect to the Wifi network.   I followed the instructions for the installation, the network is OK for other devices.  Have more older gen 3 ATV TV downstairs in the operation.    Is there a problem to have 2 ATV on the same network, or am I missing something?

    Hi Keithfromsubiaco,

    I am pleased to have the Apple TV on my TV as well and have a up and down.  Both work well, is not a problem having both on the same network.

    After going through the normal installation process, I would recommend then walk through this article.

    Get help with Wi - Fi on your Apple TV networks - Apple Support

    Note that you will want to test after each step.

    Let us know how it goes.

  • Questions about the creation of a foreign key on a table

    Hello @ll,

    during an update of the database, 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 werteartarchiv_pt table referencing werteart.

    Some statistics on the size 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 (apologies for the German error message):

    sqlplus ORA-00604: Fehler auf rekursiver SQL-ebony 1
    sqlplus ORA-01652: Temp-Segment kann nicht um 128 in Tablespace TEMPS00 judgements

    The statement that I used:

    ALTER table werteartarchiv_pt
    Add constraint werteartarchiv_pt_fk1
    foreign key (rail, werteartadresse, merkmale)
    Reference werteart (rail, werteartadresse, merkmale)
    on delete cascade
    at the delayed start can be delayed;

    So, the problem seems to be that Oracle needs a lot of temporary tablespace to generate foreign key and I do not know how and why.

    My questions now are, and I hope that someone is there who can answer all or part of it:

    (1) why Oracle should temporary tablespace to create the foreign key? The foreign key uses the same columns as the primary key.

    is 2 (a) possible to change the statement without using the temporary tablespace?

    2 (b) if it is not possible to avoid the use of temporary storage space, is there a formula how to calculate the necessary temporary tablespace?

    (3) is it possible to modify data in tables while the foreign key is created or is the whole table locked during the process?

    Any help or advice is appreciated.

    Kind regards
    Bjoern

    RollinHand wrote:
    My questions now are, and I hope that someone is there who can answer all or part of it:

    (1) why Oracle should temporary tablespace to create the foreign key? The foreign key uses the same columns as the primary key.

    Because it is data validation to ensure that the foreign key are violated. If you had specified NOVALIDATE ACTIVATE in its creation then the existing data in the table should be checked and the statement must fill out instantly (future data added is enabled by the constraint).

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28310/general005.htm

    Search for "Enable Novalidate constraint State"

  • Hard drive failure: have a few questions!

    Some info about my computer:
    • Toshiba Satellite laptop P755
    • There was more than one year
    • Windows 7 Home Edition Premium came with the laptop.
    Hello
    In the last few days I received an error saying that my hard drive can fail at any time, and for this reason, I have to back up my files. I run that a full backup as Windows Error Message had recommended that I do, but instead I just backed up my important files on a USB key. Finally, I know that my hard drive will fail, and at this point I am waiting. I am looking to buy a new HDD replacement , but I have a few questions that NEED to know before you proceed with the replacement of my current hard drive. Since I'm getting a new hard drive, should I buy a new key to activate Windows 7? Under my laptop, I have a Windows 7 Home Premium product key and my friend said that I will be able to borrow his Windows 7 Home Premium CD to install the operating system on my new hard drive. So do I still need to buy a new copy of Windows 7? I looked around forums and some people responded by saying that I won't need to buy a new copy of Windows 7 and when I install Windows on the new drive, it will be recognized that I had a genuine Windows 7 operating system. I had also heard tell that if I turned off my key using CMD, then I could re - use my key to install Windows. That's really all that I have questions, and I hope that this gets answered. Thank you.
    I also ran a scan through my hard drive and here are the results.

    Hello

    When the new drive arrives and it is installed, you shouldn't have any problems activating you replace just the hard drive and not the motherboard. The motherboard is what is important in the main OEM installations. If you have a COA sticker at the bottom of the laptop, or elsewhere, it will be what you use to activate Windows.

    If you have however poorly (you shouldn't), don't panic, just follow the phone activation method and you will be straightened out:

    1. start > Search > in the search box, type slui.exe 4
     
    2. press the key "enter".
     
    3. Select your country in the list
     
    4. choose the phone Activation
     
    5. stay on the phone and wait for an operator to help you, do not press the buttons, etc. Once you get an operator, explain your activation trouble and you should be set.

    Kind regards

    Patrick

  • Optimize the foreign key for the removal of the cascade constraint.

    Hello

    JDeveloper version: 11.1.2.3.0

    I saw this blog and found something new to me: http://snag.gy/qI6dY.jpg

    Jdeveloper user interface, there is an option to select all tables to select the foreign key and set it for the removal of the waterfall.

    My project is deployed on multiple databases. I wonder where this change is registered. None of the project files is modified.

    Can I make this change (from limitations to the waterfall) for each database that I use?

    Here is the blog where I saw that: http://tompeez.wordpress.com/2013/04/22/master-detail-insertdelete-sample/

    I have my object associations optimized for the removal of the waterfall, but without the option above together, I always get constraint violations...

    Concerning

    Not sure however if you set the option the DOF looks like

    "EMP_JOB_FK' FOREIGN KEY ('JOB_ID') CONSTRAINT
    REFERENCES 'HR '. "" SELECT JOBS "("JOB_ID') WE DELETE CASCADE

    If you set the option to cascade for fk Job_id from the employees table.

    Timo

  • How to check where the table field has been used as a foreign key in the database

    Hi I have a field in my table Office I had office_code field, this field has been used in the tables of diffirent as foreign key is a sql I can wirte to see all the tables that have used this field as a foreign key

    Edited by: adf009 09/05/2013 10:37

    Edited by: adf009 09/05/2013 10:38

    Check this box

    SELECT * FROM user_constraints WHERE table_name='EMP' and CONSTRAINT_TYPE='R';
    

    Type = 'R' means referential integrity constraint type.

  • "ORA-00904 of invalid identifier", what's the problem?

    Hey,.

    I am trying to create very basic (via Script Editor) 4 tables in Application Express 4.1.0.00.32 and get this error and cannot understand why. If anyone can point out where I am going wrong would be perfect!

    Here's the script:

    ----------

    Drop TABLE County CASCADE CONSTRAINTS ;

    Drop TABLE City CASCADE CONSTRAINTS ;

    Drop TABLE Offence CASCADE CONSTRAINTS ;

    Drop TABLE Region CASCADE CONSTRAINTS ;


    CREATE TABLE County (

    PRIMARY County_Name VARCHAR2()55) KEY

        Rental VARCHAR2 (55) ,

        Details VARCHAR2 (222) );


    CREATE TABLE Offence (

        Offence_ID NUMBER (3) PRIMARY KEY ,

    Offence_Desc VARCHAR2()333)

    Offence_Type VARCHAR2()111() NOT NULL

        Date DATE NOT NULL ,

        Time NUMBER (5) ,

    County_Name VARCHAR2()55( ) REFERENCES County()County_Name)

    City_Name VARCHAR2()55( ) REFERENCES City()short-term()

    Region_Name VARCHAR2()55( ) REFERENCES region()rated()()


    CREATE TABLE City (

    County_Name VARCHAR2()55( ) REFERENCES County()County_Name)

    PRIMARY City_Name VARCHAR2()55) KEY

        PostCode VARCHAR (8) NOT NULL ,

        House # NUMBER (3) NOT NULL ,

        Street VARCHAR2 (55) ,

        Town VARCHAR2 (55) ,

        Building_Name VARCHAR2 (55) );

    CREATE TABLE Region (

    PRIMARY Region_Name VARCHAR2()55) KEY

        City VARCHAR2 (55) NOT NULL ,

        Est_Population NUMBER (9) NOT NULL );

    -----------


    The error I get in the summary when I run the script is:

    6 «»0.00CREATE TABLE offence (Offence_ID NUMBER PRIMARY KEY (3),)"ORA-00904: invalid identifier.

    So I guess it's related to the "Offence_ID" line (designed as the primary key / identifier), but I don't see a problem.

    Any help is greatly appreciated!

    The DATE is an Oracle reserved word.

    Oracle reserved words and keywords

    SQL > create table test_tbl

    () 2

    3 date default sysdate

    4  );

    date default sysdate

    *

    ERROR at line 3:

    ORA-00904: invalid identifier

    SQL > create table test_tbl

    () 2

    3 'DATE' date default sysdate

    4  );

    Table created.

    I wouldn't recommend do not name your DATE column, but to use something like Offence_date instead.

  • Is a foreign key MUST have a UNIQUE or PK column as a reference?

    First I tried, from what I saw Yes it must be Unique or PK. Secondly, I am pretty sure that I read somewhere where there are PK or unique. Thirdly, I checked oradocs and other pages, the thing ends, I owe an answer

    Constraint foreign key (also called a constraint referential integrity) designates a column as a foreign key and establishes a relationship between this foreign key and a primary or unique key specified, called the referenced key.


    This implies, but does not explicitly specify that it MUST be a PK or a SINGLE.


    Basically I want a simple yes/no answer just to give me some peace of mind. I don't want to waste any time, but changes to the oracle from time to time, and I'd rather have a confirmation from someone with more knowledge/experience.


    Thank you!

    Yes.

    This same document you are referencing tells you what are the rules for the creation of a foreign key.

    Data integrity

    Foreign key constraints

    Whenever two tables have one or more common columns, Oracle database can apply the relationship between the two tables with a foreign key, also called a referential integrity constraint constraint. The constraint requires that for each value in the column on which the constraint is defined, the value in the other specified that another table and column must match. An example of a referential integrity rule is that an employee may work for only one Department.

    Table 5-2 lists the terms associated with referential integrity constraints.

    Table 5-2 referential integrity constraint conditions

    Term Definition

    Foreign key

    The column or set of columns included in the constraint definition that refers to a key that is referenced. For example, the department_id column employees is a foreign key that refers to the department_id column of departments .

    Foreign keys can be described as several columns. However, a composite foreign key must refer to a primary or unique key with the same number of columns and the same types of data.

    The value of the foreign keys can be either the primary or unique key value referenced or be null. If any column of a composite foreign key is null, then the portions not null the key do not match any corresponding part of a parent key.

    Referenced key

    The unique key or the primary key of the table referenced by a foreign key. For example, the department_id column departments is the key referenced to the department_id column of employees .

    Table dependent or child

    The table containing the foreign key. This table is based on the values present in the primary or unique key referenced. For example, the employees table is a child of departments .

    Referenced or the parents table

    The table that is referenced by the foreign key of the child table. It is the key to this table reference that determines whether specific inserts or updates are allowed in the child table. For example, the departments table is a parent of employees .

    The first three terms defined in the table EXPLICITLY State references to the 'core' or 'unique' keys to the parent.

    The doc also refers to the Application Developer Guide:

    Maintaining the integrity of the data in Database Applications

    Foreign key references a primary key by default

    If the list of columns is not included in the REFERENCES option when you set a FOREIGN KEY constraint (simple or composite column), then Oracle database assumes that you want to reference the primary key of the specified table. You can also explicitly specify the columns to reference the table parent in parentheses. Oracle database checks automatically to check this list of column refers to a primary or unique to the parent table key. If it isn't, an informative error is returned.

    That the entire paragraph is as explicitly as it gets.

    No list of columns? Oracle then checks for a primary key.

    There is a list of columns? Then Oracle 'control to verify this list of column made reference to a primary or unique key'...

  • Whenever I use Adobe Creative Cloud, I have the same question; do you want to allow the following program to make changes to this computer. Whenever I click OK. But the question is always every time. I have download the new versin of the designer c.

    See the previous question.

    Please follow every time I use Adobe Creative Cloud, I have the same question, you want to allow the following program to make changes to this computer. Whenever I click OK. But the question is always every time. I have download the new versin of the creative c

    Double Post

  • I have a question please. Are the activation of wifi, Bluetooth and 3G while I'm outdoor consume the battery of my iPhone (6 s) and reduce its life expectancy?

    I have a question please. Are the activation of wifi, Bluetooth and 3G while I'm outdoor consume the battery of my iPhone (6 s) and reduce its life expectancy?

    If you want your Apple Watch to stay connected to the phone, you need to keep compatible BlueTooth.

    All functions of the phone will use up the battery life. Some things more than others. Screen brightness, low cell signal strength and location services are major culprits. If you are having battery problems, see this article:

    http://www.scottyloveless.com/blog/2014/the-ultimate-guide-to-solving-iOS-batter y-drain

    I don't know what it means being out of doors has to do with the question.

  • I forgot my secret question, answer and the second email but I have the password of my ID Apple and my phone number. I want to receive by email for my secret to my Apple ID issue because it is a gmail account. Please help me

    I forgot my secret question, answer and the second email but I have the password of my ID Apple and my phone number. I want to receive by email for my secret to my Apple ID issue because it is a gmail account. Please help me

    You have to ask Apple to reset your security questions. To do this, click here and choose a method; If this page does not list one for your country or if you are unable to call, complete and submit this form.


    (139026)

  • Hello Mr President! I have a few questions about the Word report generation please.1.How can I add a border to a page in word? 2. How can I add gridlines to a table generated related word?. Can 3. how I add a border to a picture of the Word report?. Thank

    Hello!

    Sir, I have a few questions about generating word reports using (C language in labwindows) please.

    1. How can I add a border to a page in word?

    2. How do I add border lines and grid to a table generated in Word report (not "cvi control table"inserted from gui, I wonder about the table generated in Word report)?

    3. How can I fill a table cell of report word with the data type other than 'character '.

    And sir a question on the use of the timer in labwindows cvi please.

    Sir, I'm trying to set a time minimum interval timer to 1millisecond (0.001 s), that I have set, timer cares about the interval set by me he only meets the minimum default time interval which is, I think as 10milliseconds (I'm using windows xp service Pack 3 version 2002).

    Concerning

    Imran

    Pakistan

    Have you read this statement ? It explains how to set the registry value:

    If the REG_SZ useDefaultTimer does not already exist, you must create it under HKEY_LOCAL_MACHINE\SOFTWARE\National Instruments\CVI Run-Time Engine\cvirte. "" This can be done navigate to the appropriate folder, and then click Edit "New" string value. Then, click on means the name of the new value created, select Rename, and then specify useDefaultTimer as the name. Finally, double click on the name and specify the value True or False.

Maybe you are looking for