我有两张桌子
websites
contain feilds
(SiteID,SiteName)
websitesdata
contain feilds
(SiteID,ip,hits,...)
在更新级联上将SiteID外键设置为删除级联上的网站(SiteID)。
当我删除
中的记录时websites.SiteID
网站数据中SiteID = sites.SiteID的所有记录都将被删除。 但当我更新网站中的记录。我得到了 错误#1452。
如果在websitedata中没有网站数据记录,那么网站数据.SiteID = sites.SiteID我可以更新网站.SiteID值。
我试过了 SET foreign_key_checks = 0; 在两张桌子上,但没有工作。
抱歉我的英文!
修改
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 30, 2013 at 12:47 PM
-- Server version: 5.5.16
-- PHP Version: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `begardin`
--
-- --------------------------------------------------------
--
-- Table structure for table `websites`
--
CREATE TABLE IF NOT EXISTS `websites` (
`SiteID` bigint(20) NOT NULL AUTO_INCREMENT,
`SiteName` varchar(50) COLLATE utf32_unicode_ci NOT NULL,
PRIMARY KEY (`SiteID`,`SiteName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf32 COLLATE=utf32_unicode_ci AUTO_INCREMENT=8 ;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 30, 2013 at 12:46 PM
-- Server version: 5.5.16
-- PHP Version: 5.3.8
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `begardin`
--
-- --------------------------------------------------------
--
-- Table structure for table `websitesdata`
--
CREATE TABLE IF NOT EXISTS `websitesdata` (
`SiteID` bigint(20) NOT NULL,
`day` date NOT NULL,
`ip` varchar(15) COLLATE utf32_unicode_ci NOT NULL,
`Hits` bigint(20) unsigned NOT NULL,
PRIMARY KEY (`SiteID`,`day`,`ip`),
KEY `SiteID` (`SiteID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf32 COLLATE=utf32_unicode_ci;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `websitesdata`
--
ALTER TABLE `websitesdata`
ADD CONSTRAINT `websitesdata_ibfk_3` FOREIGN KEY (`SiteID`) REFERENCES `websites` (`SiteID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `dd` FOREIGN KEY (`SiteID`) REFERENCES `websites` (`SiteID`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `websitesdata_ibfk_1` FOREIGN KEY (`SiteID`) REFERENCES `websites` (`SiteID`) ON DELETE CASCADE,
ADD CONSTRAINT `websitesdata_ibfk_2` FOREIGN KEY (`SiteID`) REFERENCES `websites` (`SiteID`) ON UPDATE CASCADE;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;