SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    cant create table ..... (erno: 150)

    Well morning everybody,

    so actually i have to do some work for my coming classtest, everything is working fine ... just the last part of my sql script.

    Code:
    CREATE DATABASE IF NOT EXISTS db_schueler;
    USE db_schueler;
    
    CREATE TABLE IF NOT EXISTS tbl_schueler (
    			id INT(4) NOT NULL AUTO_INCREMENT,
    			name CHAR(12) NOT NULL,
    			vorname CHAR(12) NOT NULL,
    			adresse char(50) NOT NULL,
    			stadt CHAR(20) NOT NULL,
    			versetzung12 BIT NOT NULL,  -- 1/0 bzw. Ja/Nein
    			PRIMARY KEY (id)
    			);
    			
    CREATE TABLE IF NOT EXISTS tbl_fach (
    			fach_id INT(4) NOT NULL AUTO_INCREMENT,
    			tbl_schueler_id INT(4),
    			deutsch CHAR(12) NOT NULL,
    			mathe CHAR(12) NOT NULL,
    			englisch CHAR(12) NOT NULL,
    			datenbank CHAR(12) NOT NULL,
    			programmiertechnik CHAR(12) NOT NULL,
    			betriebnetzwerke CHAR(12) NOT NULL,
    			PRIMARY KEY (fach_id),
    			FOREIGN KEY (tbl_schueler_id) REFERENCES tbl_schueler(id)
    			);
    			
    CREATE TABLE IF NOT EXISTS tbl_zensuren (
    			zensuren_id INT(4) NOT NULL AUTO_INCREMENT,
    			schueler_versetzung12 BIT NOT NULL,  -- 1/0 bzw. Ja/Nein
    			prüfung BIT NOT NULL, -- 1/0 bzw. Ja/Nein
    			PRIMARY KEY(zensuren_id),
    			FOREIGN KEY(schueler_versetzung12) REFERENCES tbl_schueler(versetzung12)
    			);
    I am getting this Error Cant Create table 'db.schueler.tbl_zensuren' (erno: 150)
    I Found out that this error stays in connection with the foreign key, but i have no idea.

    I Hope s.o can help me to fix this.

    Grettings

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    a foreign key must reference either a primary or unique key, i believe

    also, what would be the purpose of declaring a 1/0 column as a foreign key?
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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