I have an error syntax while creating tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • msdhh
    New Member
    • Nov 2012
    • 8

    I have an error syntax while creating tables

    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:-

    Code:
    CREATE TABLE Company
    (
    Company_Id int primary key not null,
    Company_Name varchar(255),
    )
    
    CREATE TABLE Dept
    (
    Dept_Id int not null,
    DeptName varchar(255),
    Company_Id int,
    Employee_Id int,
    Primary key (Dept_Id),
    CONSTRAINT fk_Company_Id FOREIGN KEY (Company_Id)
    REFERENCES Company(Company_Id)
    CONSTRAINT fk_Employee_Id FOREIGN KEY (Employee_Id)
    REFERENCES Employee(Employee_Id)
    )
    
    CREATE TABLE Employee
    (
    Employee_Id int not null,
    EmployeeName varchar (255)
    )
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    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.

    Comment

    Working...