Results 1 to 2 of 2

Thread: beginner in need of help

  1. #1
    Join Date
    Jan 2005
    Location
    liv
    Posts
    2

    beginner in need of help (anyone?)

    I have created two tables

    CREATE TABLE Topic (
    Topic_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Topic_name TEXT,
    Topic_info TEXT
    );

    CREATE TABLE Img (
    Img_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Img_name TEXT,
    Img_author TEXT
    );

    What i want to do is include the Img_ID in the Topic table(as a foreign key??) so i can refer to it through that table.

    do i do it like this:

    CREATE TABLE Topic (
    Topic_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Topic_name TEXT,
    Topic_info TEXT,
    Img_Id INT NOT NULL AUTO_INCREMENT FOREIGN KEY,
    );

    any help would be great thanks in advance
    g
    Last edited by godonholiday; 01-02-2005 at 03:25 PM.

  2. #2
    Join Date
    Feb 2003
    Posts
    1,048
    Here are two ways to do it:

    1. CREATE TABLE Img (
    Img_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Img_name TEXT,
    Img_author TEXT
    );

    CREATE TABLE Topic (
    Topic_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Topic_name TEXT,
    Topic_info TEXT,
    Img_ID INT NOT NULL REFERENCES Img(Img_ID)
    );


    2. CREATE TABLE Img (
    Img_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Img_name TEXT,
    Img_author TEXT
    );

    CREATE TABLE Topic (
    Topic_ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Topic_name TEXT,
    Topic_info TEXT,
    Img_ID INT NOT NULL
    );

    ALTER TABLE Topic
    ADD CONSTRAINT fk_img_id
    FOREIGN KEY (Img_ID)
    REFERENCES Img (Img_ID);

Posting Permissions

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