954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

SQL Creating Table

This is homework. I have to create two tables with certain constraints. However, I keep getting syntax errors, and I really have no clue exactly how to format it because there are so many different 'templates' out there. Here is what I have so far.

create table Departments
 (Department_ID number
	PRIMARY KEY,
  Dept_Name varchar2(25)
	NOT NULL UNIQUE,
  City varchar2(50)
	NOT NULL,
  Budget_Code char(5)
	NOT NULL UNIQUE,
  Mailstop char(3)
	NOT NULL);

The constraints are in all caps. Also, I need to know how to do multiple constraints. Can someone help me on this?
The second table I have:

create table Employees
 (Employee_ID number
	PRIMARY KEY,
  Last_Name varchar2(50)
	NOT NULL,
  First_Name varchar2(50)
	NOT NULL,
  State char(2),
  Zipcode char(5),
  e-mail varchar2(100)
	UNIQUE,
  Gender char(1)
	NOT NULL CHECK(Gender="M" OR "F"),
  Hire_Date date
	NOT NULL,
  Department_ID Number
	NOT NULL FOREIGN KEY (Department_ID) references DEPARTMENTS(DEPARTMENT_ID));


If anyone sees errors here, please let me know. I'm still pretty new at this.

iamthesgt
Junior Poster
107 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

Oracle does not accepts the "-" sign for the columns. If you want your column to be called e-mail then make it "e-mail".
And your foreign key declaration is not good,

dan420
Newbie Poster
13 posts since Dec 2009
Reputation Points: 36
Solved Threads: 0
 

Okay, thanks. So how should the foreign key declaration go? I followed a template I found, but I guess it may be wrong.

iamthesgt
Junior Poster
107 posts since Nov 2010
Reputation Points: 10
Solved Threads: 0
 

here is an example
CREATE TABLE products
( product_id numeric(10) not null,
supplier_id numeric(10) not null,
CONSTRAINT fk_supplier
FOREIGN KEY (supplier_id)
REFERENCES supplier(supplier_id)
);

dan420
Newbie Poster
13 posts since Dec 2009
Reputation Points: 36
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: