Thread: Database help

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Angry Database help


    I'm extremely new to this (n00b!) but I am having some troubles creating a table and I suspect the foreign key is the culprit.

    Here's what I have done so far:

    Create database test;
    Use test;
    Create Table students (sid char(20), name char(20), login char(20), age integer, gpa real);
    Insert into students (sid,name,login,age,gpa) values (1, ‘Wayne’, ‘bwayne@123.com’,25, 3.95);
    Insert into students (sid,name,login,age,gpa) values (1, ‘Kent’, ‘ckent@123.com’,27, 3.91);
    Select * from students;
    Update students s set s.age = s.age +1, s.gpa = s.gpa -1 where s.sid = 1;
    Select * from students;
    Alter table students add constraint unique (name,age);
    Alter table students add constraint studentskey primary key (sid);

    When I attempt to add the following I get 'Error 1005 (HY000): Can't create table 'testing.enrolled' (errno: 150)

    create table enrolled (studid char(20),cid char(20),grade char(10),primary key (studid, cid),foreign key (studid) references students);


    Any help would be greatly appreciated! As I said, I'm very new to this and am probably doing something easy, incorrectly.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    OMG. I'm an idiot.

IMN logo majestic logo threadwatch logo seochat tools logo