title: How MySQL one to many and one to one relationships are defined?
body: <p>I was referring these to Hibernate tuts: <a href="https://www.journaldev.com/2924/hibernate-one-to-many-mapping-annotation" rel="nofollow noreferrer">1</a>, <a href="https://www.journaldev.com/2916/hibernate-one-to-one-mapping-example-annotation" rel="nofollow noreferrer">2</a>.</p>
  
  <p>I was not able to understand how one to one and one to many relationships are defined in MySQL tables. </p>
  
  <p>This is SQL for one to many relationship:</p>
  
  <pre><code>CREATE TABLE `Cart` (
    `cart_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `total` decimal(10,0) NOT NULL,
    `name` varchar(10) DEFAULT NULL,
    PRIMARY KEY (`cart_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
  
  CREATE TABLE `Items` (
    `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `cart_id` int(11) unsigned NOT NULL,
    `item_id` varchar(10) NOT NULL,
    `item_total` decimal(10,0) NOT NULL,
    `quantity` int(3) NOT NULL,
    PRIMARY KEY (`id`),
    KEY `cart_id` (`cart_id`),
    CONSTRAINT `items_ibfk_1` FOREIGN KEY (`cart_id`) REFERENCES `Cart` (`cart_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>This is SQL for one to one relationship:</p>
  
  <pre><code>-- Create Transaction Table
  CREATE TABLE `Transaction` (
    `txn_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
    `txn_date` date NOT NULL,
    `txn_total` decimal(10,0) NOT NULL,
    PRIMARY KEY (`txn_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;
  
  -- Create Customer table
  CREATE TABLE `Customer` (
    `txn_id` int(11) unsigned NOT NULL,
    `cust_name` varchar(20) NOT NULL DEFAULT '',
    `cust_email` varchar(20) DEFAULT NULL,
    `cust_address` varchar(50) NOT NULL DEFAULT '',
    PRIMARY KEY (`txn_id`),
    CONSTRAINT `customer_ibfk_1` FOREIGN KEY (`txn_id`) REFERENCES `Transaction` (`txn_id`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>If eyes are ok, I dont see any difference between two. Is it like this relationship cardinality constraints are implemented only at hibernate level and are not enforced by database? Or my eyes are missing something?</p>