473,385 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Primary Key Constraint

32
Hey guys. This is a school related question. My lab says the following:

1. Add a new Vendor table
a. See table above for fields and data types
b. Use your username as the table definition, i.e., userid.Vendor, instead of Demo
c. Add Primary key ProductNo as a Constraint

Okay, I created the table with the fields and data types. Now when I go to add the primary key with the constraint and I get
ERROR at line 2:
ORA-00904: "VENDOR_NO": invalid identifier

When I enter:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT ProductNo PRIMARY KEY (Vendor_No);
  3.  
This is the command the teacher listed on the paper:
Expand|Select|Wrap|Line Numbers
  1. Alter tables:
  2.     Adding a single field as a Primary Key 
  3.         ALTER TABLE tablename ADD
  4.                               CONSTRAINT pk_name PRIMARY KEY (column_name);


What am I doing wrong?
Dec 15 '07 #1
13 3560
mwasif
802 Expert 512MB
Moved to Oracle Forum.
Checkout this post.
Dec 16 '07 #2
amitpatel66
2,367 Expert 2GB
Hi,

Please make use of code tags when ever you post aqny code in this forum

Thanks
MODERATOR
Dec 16 '07 #3
amitpatel66
2,367 Expert 2GB
Hey guys. This is a school related question. My lab says the following:

1. Add a new Vendor table
a. See table above for fields and data types
b. Use your username as the table definition, i.e., userid.Vendor, instead of Demo
c. Add Primary key ProductNo as a Constraint

Okay, I created the table with the fields and data types. Now when I go to add the primary key with the constraint and I get
ERROR at line 2:
ORA-00904: "VENDOR_NO": invalid identifier

When I enter:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT ProductNo PRIMARY KEY (Vendor_No);
  3.  
This is the command the teacher listed on the paper:
Expand|Select|Wrap|Line Numbers
  1. Alter tables:
  2.     Adding a single field as a Primary Key 
  3.         ALTER TABLE tablename ADD
  4.                               CONSTRAINT pk_name PRIMARY KEY (column_name);


What am I doing wrong?
Please post your table structure for reference?
Dec 16 '07 #4
Prosdo
32
Please post your table structure for reference?
Sorry about posting it in the wrong forum. Here is my table setup:

Dec 17 '07 #5
Prosdo
32
I see my dumb error on that one. But I am having a problem with the foreign key. My paper says:

3. Alter Vendor table to add constraint of Vendor.Zip_Code as a Foreign Key field references Zipcode.Zip_code field.

Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tablename ADD
  2.                               CONSTRAINT fk_name FOREIGN KEY (column_name)
  3.                               REFERENCES tablename (column_name);


I typed in:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
  3.                               REFERENCES slp5065.zipcode.zip_code (zip_code);
I got the error:
CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
*

ERROR at line 2:
ORA-00904: : invalid identifier

Here are my tables:

Dec 17 '07 #6
Prosdo
32
Can anyone help? I have to turn it in by midnight est. Which is in 38 minutes. I e-mailed my teacher about this a while ago and he hasn't gotten back to me.
Dec 17 '07 #7
amitpatel66
2,367 Expert 2GB
I see my dumb error on that one. But I am having a problem with the foreign key. My paper says:

3. Alter Vendor table to add constraint of Vendor.Zip_Code as a Foreign Key field references Zipcode.Zip_code field.

Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tablename ADD
  2.                               CONSTRAINT fk_name FOREIGN KEY (column_name)
  3.                               REFERENCES tablename (column_name);


I typed in:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
  3.                               REFERENCES slp5065.zipcode.zip_code (zip_code);
I got the error:
CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
*

ERROR at line 2:
ORA-00904: : invalid identifier

Here are my tables:

Please let me know the following:

What is slp5065?? a schema name?
What is Zipcode?? a table name??
And I dont find your table structure.Please POST your table structure.
Dec 17 '07 #8
Prosdo
32
Please let me know the following:

What is slp5065?? a schema name?
What is Zipcode?? a table name??
And I dont find your table structure.Please POST your table structure.
Sorry very new to Oracle and all. slp5065 is my user name. When we did other projects for the class they were named demo.customer. So for each student we had to just put our userid.tablename. slp5065.Zipcode is a table. I guess this is the table structure. If it isn't please let me know and I will try to find out what it is.

Dec 17 '07 #9
rpnew
188 100+
I see my dumb error on that one. But I am having a problem with the foreign key. My paper says:

3. Alter Vendor table to add constraint of Vendor.Zip_Code as a Foreign Key field references Zipcode.Zip_code field.

Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE tablename ADD
  2.                               CONSTRAINT fk_name FOREIGN KEY (column_name)
  3.                               REFERENCES tablename (column_name);


I typed in:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
  3.                               REFERENCES slp5065.zipcode.zip_code (zip_code);
I got the error:
CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
*

ERROR at line 2:
ORA-00904: : invalid identifier

Here are my tables:


hi,

First tell me in your query what is following......
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
  3.                               REFERENCES slp5065.zipcode.zip_code (zip_code);
It should be tablename contains the column you are referencing as foreign key...

From your code it seems that you have two tables named slp5065.vendor and slp5065.zipcode and if i'm not wrong change your query to this..
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE slp5065.vendor ADD
  2.                               CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
  3.                               REFERENCES slp5065.zipcode(zip_code);
  4.  
As per my knwoledge...... If i'm wrong somewhere let me know........

Regards,
RP
Dec 17 '07 #10
Prosdo
32
Thank you for the reply. I tried what you said and I got the following error:

CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
*

ERROR at line 2:
ORA-00904: : invalid identifier
Dec 17 '07 #11
amitpatel66
2,367 Expert 2GB
Thank you for the reply. I tried what you said and I got the following error:

CONSTRAINT slp5065.vendor.zip_code FOREIGN KEY (vendor_zip_code)
*

ERROR at line 2:
ORA-00904: : invalid identifier
Do the following and paste the output here:

Expand|Select|Wrap|Line Numbers
  1.  
  2. SQL> DESC <table_name>
  3.  
  4.  
In the above code replace table_name with your table name and paste the output here for my reference
Dec 17 '07 #12
Prosdo
32
slp5065.vendor table
Name Null? Type
VENDOR_NO NOT NULL NUMBER(6)
VENDOR_NAME VARCHAR2(30)
VENDOR_ADDRESS VARCHAR2(35)
VENDOR_ZIP_CODE NOT NULL NUMBER(38)

slp5065.zipcode table
Name Null? Type
ZIP_CODE NOT NULL NUMBER(5)
ZIP_CITY VARCHAR2(15)
ZIP_STATE VARCHAR2(2)
Dec 17 '07 #13
amitpatel66
2,367 Expert 2GB
slp5065.vendor table
Name Null? Type
VENDOR_NO NOT NULL NUMBER(6)
VENDOR_NAME VARCHAR2(30)
VENDOR_ADDRESS VARCHAR2(35)
VENDOR_ZIP_CODE NOT NULL NUMBER(38)

slp5065.zipcode table
Name Null? Type
ZIP_CODE NOT NULL NUMBER(5)
ZIP_CITY VARCHAR2(15)
ZIP_STATE VARCHAR2(2)
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. ALTER TABLE vendor_table ADD FOREIGN KEY (vendor_zip_code) REFERENCES zipcode(zip_code);
  3.  
  4.  
Dec 18 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: John Simmons | last post by:
How is it that even though I have the column "username" in my database set as a Primary key, using my PHP script to add new users to the database works without any errors even when signing up using...
1
by: js | last post by:
I am trying to create a primary key constraint on a view in the following statement. However, I got an error ORA-00907: missing right parenthesis. If the CONSTRAINT clause is removed, then the...
9
by: Bob C. | last post by:
I want to create a 1-many relationship. Parent table has a primary key, child table has no primary key. The child table does have an index with all four fields of the parent's PK. How can I do...
3
by: William D. Bartholomew | last post by:
I'm working on a system that is very address-centric and detection of duplicate addresses is very important. As a result we have broken addresses down into many parts (DDL below, but I've left out...
1
by: | last post by:
Hi, I am getting the following error when I run my Visual Basic application: "Cannot add primary key constraint since primary key is already set for the table" I am using datasets with...
13
by: Tibor | last post by:
I am using PostgreSQL 7.4.1 (only through psql) I know, that the command ALTER TABLE OFFICES DROP PRIMARY KEY (CITY); and its foreign key equivalent: ALTER TABLE SALESREPS DROP CONSTRAINT
1
by: Kevin Murphy | last post by:
Using PG 7.4.5 on Mac OS X 10.3 ... I have a primary key that I can't destroy and can't create. One weird symptom is that when I use \d in psql to attempt to display the constraint, there is no...
9
by: danielbuus | last post by:
Hey there :) I'm using Ruby on Rails to create a migration of a legacy database on an MS SQL Server. I'd like to name my constraints myself, such as 'pk_authors', but in the cases where a table...
4
by: Peter | last post by:
I am interested in informed feedback on the use of Constraints, Primary Keys and Unique. The following SQL statement creates a Bands tables for a database of bookings Bands into Venues, where the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.