LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-12-2004, 01:49 AM   #1
mnguyen
LQ Newbie
 
Registered: Feb 2004
Location: Singapore
Posts: 13

Rep: Reputation: 0
A question about MySQL


I create these table using MySQL :

CREATE TABLE ProcessLog
(
username VARCHAR(30) NOT NULL,
PID INT UNSIGNED NOT NULL,
appPath VARCHAR(100) NOT NULL,
startTime DATETIME NOT NULL,
endTime DATETIME NULL,
UNIQUE (username, PID, startTime),
FOREIGN KEY (username) REFERENCES Users (username) ON DELETE CASCADE,
) TYPE = INNODB;


CREATE TABLE Users
(
username VARCHAR(30) NOT NULL,
email VARCHAR(30) NULL,
handphone VARCHAR(10) NULL,
PRIMARY KEY (username),
password VARCHAR(30) NOT NULL
) TYPE = INNODB;


CREATE TABLE IELog
(
username VARCHAR(30) NOT NULL,
PID INT UNSIGNED NOT NULL,

FOREIGN KEY (username)
REFERENCES Users (username)
ON DELETE CASCADE,

FOREIGN KEY (PID)
REFERENCES ProcessLog (PID)
ON DELETE CASCADE,

startTime DATETIME NOT NULL,
endTime DATETIME NULL,
URL VARCHAR(200) NOT NULL,
PRIMARY KEY (username, PID, startTime)
) TYPE = INNODB;


After adding two table Users and ProcessLog, I add the IELog table but an error msg occured like this :

titan@linux:~/working/database> mysql test < create_users_table.sql
titan@linux:~/working/database> mysql test < create_ProcessLog_table.sql
titan@linux:~/working/database> mysql test < create_IELog_table.sql
ERROR 1005 at line 1: Can't create table './test/IELog.frm' (errno: 150)

Can anyone help me ? Tks a lot.
 
Old 05-14-2004, 10:32 AM   #2
nephilim
Member
 
Registered: Aug 2003
Location: Belgium
Distribution: Debian (server), Kubuntu (desktop)
Posts: 248

Rep: Reputation: 30
rewrite your IELog script like this:

CREATE TABLE IELog
(
username VARCHAR(30) NOT NULL,
PID INT UNSIGNED NOT NULL,
startTime DATETIME NOT NULL,
endTime DATETIME NULL,
URL VARCHAR(200) NOT NULL,
PRIMARY KEY (username, PID, startTime),

FOREIGN KEY (username)
REFERENCES Users (username)
ON DELETE CASCADE,

FOREIGN KEY (PID)
REFERENCES ProcessLog (PID)
ON DELETE CASCADE

) TYPE = INNODB;

I don't think you can declare foreign keys in the middle of your field declarations.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
MySQL question... kith Linux - General 3 03-06-2004 06:40 PM
MySQL Question NoBrains Linux - Software 2 03-01-2004 10:10 PM
MySQL question TraCe66 Linux - Newbie 11 07-15-2003 02:35 PM
MySQL question ascii2k Linux - General 1 03-27-2002 04:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration