41024

no matching unique or primary key for this SQL

Question:

I'm trying to write this code

CREATE TABLE BOOK (BOOKNO NUMBER(4) PRIMARY KEY NOT NULL, BTIME NUMBER(24,22), CNAME VARCHAR2(10) , BTYPE VARCHAR2(13), TABLENO NUMBER(2), EMPNO NUMBER(4), ENAME VARCHAR2(10), BDATE DATE DEFAULT '23-MAR-13', FOREIGN KEY (CNAME) REFERENCES BOOK (CNAME));

but it shows me that I have this error for creating my foregin key

<blockquote>

ERROR at line 10:<br /> ORA-02270: no matching unique or primary key for this column-list

</blockquote>

Answer1:

<strong>Oracle/PLSQL: ORA-02270 Error</strong>

You tried to reference a table using a unique or primary key, but the columns that you listed did not match the primary key, or a primary key does not exist for this table.

CREATE TABLE BOOK (BOOKNO NUMBER(4) PRIMARY KEY NOT NULL, BTIME NUMBER(24,22), CNAME VARCHAR2(10) , BTYPE VARCHAR2(13), TABLENO NUMBER(2), EMPNO NUMBER(4), ENAME VARCHAR2(10), BDATE DATE DEFAULT '23-MAR-13', FOREIGN KEY (CNAME) REFERENCES BOOK (BOOKNO));

<strong>UPDATE</strong>

CREATE TABLE BOOK (BOOKNO NUMBER(4) PRIMARY KEY NOT NULL, BTIME NUMBER(24,22), CNAME VARCHAR2(10) NOT NULL UNIQUE, BTYPE VARCHAR2(13), TABLENO NUMBER(2), EMPNO NUMBER(4), ENAME VARCHAR2(10), BDATE DATE DEFAULT '23-MAR-13', FOREIGN KEY (CNAME) REFERENCES BOOK (CNAME));

Recommend

  • Load report failed- Crystal Report in c#
  • What sort of schema can I use to accommodate manual date based data entries?
  • Laravel 5 Eloquent where and or in Clauses
  • how to select update in the same table in mysql?
  • making my tabular form dynamic
  • Dynamically generated radiobutton by jQuery cannot be selected in IE6
  • ERROR: syntax error at or near “OVER”
  • JTable does not show anything?
  • convert a string to xml doc with jquery or the other way round
  • Creating ORACLE PL/SQL store procedures with different kind of AND conditions
  • how to get the selected value of dropdown list of asp.net and store in session variable?
  • LNK1104: cannot open file 'kernel32.lib'
  • Extending the Django 1.11 User Model
  • How to Model Ternary Relationship in CakePhp?
  • Are there any side effects from calling SQLAlchemy flush() within code?
  • Can't get plist URL in Swift
  • Can my PDF ping my server when it is opened?
  • LESS CSS how to modify parent property in mixin
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • Prevent Tomcat from caching request during starup
  • Pycharm: Marking a folder as 'sources root' is not recursive for subfolders
  • UIAlertController button function not working
  • Filter strings with regex before casting to numeric
  • Center align outputs in ipython notebook
  • Diff between two dataframes in pandas
  • Parse a date string in a specific locale (not timezone!)
  • How to get Eclipse Oxygen to run on Java 9
  • Chrome doesn't support silverlight anymore? How to solve this?
  • Syntax for setting draggablecursor property in google maps api
  • Paperclip, set path outside of rails root folder
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Modifying destination and filename of gulp-svg-sprite
  • Updated Ionic CLI but shows previous version (Windows)
  • Release, debug version and Authorization Google?
  • GridView Sorting works once only
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Hits per day in Google Big Query
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?