<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[运维进行时]]></title> 
<link>https://blog.liuts.com/index.php</link> 
<description><![CDATA[互联网运维与架构]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[运维进行时]]></copyright>
<item>
<link>https://blog.liuts.com/post//</link>
<title><![CDATA[给Mysql表添加外键]]></title> 
<author>root &lt;admin@yourname.com&gt;</author>
<category><![CDATA[MYSQL]]></category>
<pubDate>Thu, 22 May 2008 08:32:03 +0000</pubDate> 
<guid>https://blog.liuts.com/post//</guid> 
<description>
<![CDATA[ 
	<strong>创建语法</strong><br/><textarea name="code" class="sql" rows="15" cols="100">
CREATE TABLE person (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
name CHAR(60) NOT NULL,
PRIMARY KEY (id)
)type=innoDB;

CREATE TABLE shirt (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
style ENUM('t-shirt', 'polo', 'dress') NOT NULL,
color ENUM('red', 'blue', 'orange', 'white', 'black') NOT NULL,
owner SMALLINT UNSIGNED NOT NULL,
FOREIGN KEY (owner) REFERENCES PERSON(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
PRIMARY KEY (id)
)type=innoDB; 
</textarea><br/><strong>语法说明</strong><br/>RESTRICT : 只要本表格里面有指向主表的数据， 在主表里面就无法删除相关记录。一般来说，就选restrict最安全，当然也根据具体的业务而言了.cascade很cool,但是数据哗的一下就没了.<br/>CASCADE : 如果在foreign key 所指向的那个表里面删除一条记录，那么在此表里面的跟那个key一样的所有记录都会一同删掉。(常用)<br/><strong>问题原因</strong><br/>今天在Mysql中创建表时,提示错误:ERROR 1005: Can't create table (errno: 150) 在网上搜索,发现产生该错误有三种可能:<br/><div class="quote"><div class="quote-title">引用</div><div class="quote-content"><br/>&nbsp;&nbsp; 1. 外键和被引用外键类型不一样，比如integer和double<br/>&nbsp;&nbsp; 2. 找不到要被引用的列<br/>&nbsp;&nbsp; 3. 表的字符编码不一样 <br/></div></div>
]]>
</description>
</item><item>
<link>https://blog.liuts.com/post//#blogcomment</link>
<title><![CDATA[[评论] 给Mysql表添加外键]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>https://blog.liuts.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>