Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    2

    Post Unanswered: DBDesigner and FKindex?

    Im using DBDesigner and I can't figure out what is the funcionality with FKindexes?

    For example, I have a table "ajovuoro" (im sorry the names are in finnish)
    CREATE TABLE Ajovuoro (
    idAjovuoro INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    Auto_Rekisterinumero VARCHAR(20) NOT NULL,
    Kuljettaja_Hetu VARCHAR(20) NOT NULL,
    paivamaara DATE NULL,
    alkamisaika TIME NULL,
    loppumisaika TIME NULL,
    PRIMARY KEY(idAjovuoro, Auto_Rekisterinumero, Kuljettaja_Hetu),
    INDEX Ajovuoro_FKIndex1(Auto_Rekisterinumero),
    INDEX Ajovuoro_FKIndex2(Kuljettaja_Hetu)
    );

    And i have putted relations to Auto and Rekisterinumero. But why the DBD is making fields(when generating the MySQL code) INDEX Ajuovuoro_FKindex...and...FKindex2, can i just delete those. And when i want to join tables I will just do it when making MySQL queries? What for the program is making INDEX systems?

    And why the code generator is putting tree primary keys? Should i just not to make relations becouse mysql code generator is making stupid staff if I make relations between the tables.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by docc
    Im using DBDesigner and I can't figure out what is the funcionality with FKindexes?
    this is your first experience with foreign keys? perhaps you should take a tutorial

    something went wrong with your PK, it should not be 3 columns in your case, just the first one, the auto_increment

    the INDEXes generated by the tool are correct, given that those columns would be the foreign keys to the other tables

    however, in recent releases of mysql, these foreign key indexes are created by mysql automatically when the foreign key is declared

    i didn't see the actual FK definitions in your CREATE TABLE statement so i assume it is in a subsequent ALTER TABLE statement?

    as for your last question, yes you should make relationships (declare primary and foreign keys) -- most definitely, yes

    whether you use a tool such as a gui designer, or whether you write SQL by hand, you should make those relationships

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Oct 2009
    Posts
    2

    Smile

    Quote Originally Posted by r937
    this is your first experience with foreign keys? perhaps you should take a tutorial
    Correct! I havent worked with foreign keys and maybe I'm gonna look for the turorial right now - last time when I studied databases it was in university and there we were teached that you just join the tables in queries when you want to connect tables.

    table Car:
    carId(primary key)
    color: blaab..blaa

    table driver:
    driverId(primary key)
    carId(relation to the car which car is the driver using)
    blaa...blaa

    And when I would like to find out which cars are drivers driving, I have to just make query like this:

    Select * from car, driver where driver.carId = car.carID

    (and relations were just made to understand better about which tables can be joinded together and how. For sure every one but the model of relations were just made for making better queries.) None of the relations were written in the SQL code.

    But thanks for advising me, Im gonna look for tutorial first about foreing keys and then read your answer once again.

    EDIT: actually, when I looked a tutorial, this driver.carId is working like a foreign key, correct? But still i cant understand why the DBDesigner is making it so complicated by using those index staff and putting tree primarykeys.
    Last edited by docc; 10-24-09 at 12:44.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •