I have been trying to write a database schema in mysql, and I cant
figure this out.
Here is a database schema
DROP DATABASE IF EXISTS d;
CREATE DATABASE d;
USE d;
CREATE TABLE t (
tid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE s (
sid INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
tid INT NOT NULL REFERENCES t(tid),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
I thought this would work, at least that is what the manual says.
I also tried Foreign Key instead of references, but I am having trouble
using Hibernate.
But I dont think it is referencing the foreign key properly.
When I back up my schema with the administrator tool, it does not have
the foreign key referenced.
I am using Server version 4.1.14
What am I doing wrong?
Here is the back up database schema
Thanks
Kal
-- MySQL Administrator dump 1.4
--
-- ------------------------------------------------------
-- Server version 4.1.14
/*!40101 SET @OLD_CHARACTER_ SET_CLIENT=@@CH ARACTER_SET_CLI ENT */;
/*!40101 SET @OLD_CHARACTER_ SET_RESULTS=@@C HARACTER_SET_RE SULTS */;
/*!40101 SET @OLD_COLLATION_ CONNECTION=@@CO LLATION_CONNECT ION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_UNIQUE_CHE CKS=@@UNIQUE_CH ECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KE Y_CHECKS=@@FORE IGN_KEY_CHECKS,
FOREIGN_KEY_CHE CKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@ @SQL_MODE, SQL_MODE='NO_AU TO_VALUE_ON_ZER O'
*/;
--
-- Create schema d
--
CREATE DATABASE /*!32312 IF NOT EXISTS*/ d;
USE d;
--
-- Table structure for table `d`.`s`
--
DROP TABLE IF EXISTS `s`;
CREATE TABLE `s` (
`sid` int(11) NOT NULL auto_increment,
`tid` int(11) NOT NULL default '0',
PRIMARY KEY (`sid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `d`.`s`
--
/*!40000 ALTER TABLE `s` DISABLE KEYS */;
LOCK TABLES `s` WRITE;
UNLOCK TABLES;
/*!40000 ALTER TABLE `s` ENABLE KEYS */;
--
-- Table structure for table `d`.`t`
--
DROP TABLE IF EXISTS `t`;
CREATE TABLE `t` (
`tid` int(11) NOT NULL auto_increment,
PRIMARY KEY (`tid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Dumping data for table `d`.`t`
--
/*!40000 ALTER TABLE `t` DISABLE KEYS */;
LOCK TABLES `t` WRITE;
UNLOCK TABLES;
/*!40000 ALTER TABLE `t` ENABLE KEYS */;
/*!40101 SET SQL_MODE=@OLD_S QL_MODE */;
/*!40014 SET FOREIGN_KEY_CHE CKS=@OLD_FOREIG N_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@ OLD_UNIQUE_CHEC KS */;
/*!40101 SET CHARACTER_SET_C LIENT=@OLD_CHAR ACTER_SET_CLIEN T */;
/*!40101 SET CHARACTER_SET_R ESULTS=@OLD_CHA RACTER_SET_RESU LTS */;
/*!40101 SET COLLATION_CONNE CTION=@OLD_COLL ATION_CONNECTIO N */;
/*!40101 SET CHARACTER_SET_C LIENT=@OLD_CHAR ACTER_SET_CLIEN T */;