By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,288 Members | 1,695 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,288 IT Pros & Developers. It's quick & easy.

I have an error syntax while creating tables

P: 8
Hi there,

I have a problem when i want to create tables, I want to create three tables Company, Employee and department.
department table has two foreign key the employee_Id and the company_Id but there is a syntax error can you please fix it.

here is the code:-

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE Company
  2. (
  3. Company_Id int primary key not null,
  4. Company_Name varchar(255),
  5. )
  8. (
  9. Dept_Id int not null,
  10. DeptName varchar(255),
  11. Company_Id int,
  12. Employee_Id int,
  13. Primary key (Dept_Id),
  14. CONSTRAINT fk_Company_Id FOREIGN KEY (Company_Id)
  15. REFERENCES Company(Company_Id)
  16. CONSTRAINT fk_Employee_Id FOREIGN KEY (Employee_Id)
  17. REFERENCES Employee(Employee_Id)
  18. )
  20. CREATE TABLE Employee
  21. (
  22. Employee_Id int not null,
  23. EmployeeName varchar (255)
  24. )
Nov 6 '12 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 10K+
P: 12,430
It would help if you gave us the specific error messages. But I can see a couple of errors right off the bat.

1) You're missing a comma at the end of line 15.
2) You can't reference the table Employee when you haven't created it yet.
Nov 6 '12 #2

Post your reply

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