简体   繁体   English

删除/更新mysql或在代码中处理此问题(例如PHP)

[英]mysql on Delete/Update or handle this in Code (e.g. PHP)

I have some problems to find a decission for an implementation. 我有一些问题需要找到一个实现的decission。

I have to design a new database using mysql. 我必须使用mysql设计一个新的数据库。 Now I found that I can do mysqlinternal actions on update or delete (NULL/NO ACTION / CASCADE). 现在我发现我可以在更新或删除时执行mysqlinternal操作(NULL / NO ACTION / CASCADE)。

EXAMPLE USING ON DELETE MYSQL INTERNAL: 使用删除MYSQL内部的示例:

CREATE  TABLE IF NOT EXISTS `mydb`.`users` (
  `idusers` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `name` CHAR(30) NOT NULL ,
  `mail` CHAR(50) NOT NULL ,
  PRIMARY KEY (`idusers`) )
ENGINE = InnoDB;


CREATE  TABLE IF NOT EXISTS `mydb`.`avatars` (
  `users_idusers` INT UNSIGNED NOT NULL ,
  `size` VARCHAR(45) NOT NULL ,
  `color` VARCHAR(45) NOT NULL ,
  `weight` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`users_idusers`) ,
  CONSTRAINT `fk_avatars_users`
    FOREIGN KEY (`users_idusers` )
    REFERENCES `mydb`.`users` (`idusers` )
    ON DELETE CASCADE
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

Or is this way better and do each update delete completly from Application code: 或者这样做更好,每次更新从应用程序代码完全删除:

CREATE  TABLE IF NOT EXISTS `mydb`.`users` (
  `idusers` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
  `name` CHAR(30) NOT NULL ,
  `mail` CHAR(50) NOT NULL ,
  PRIMARY KEY (`idusers`) )
ENGINE = InnoDB;



CREATE  TABLE IF NOT EXISTS `mydb`.`avatars` (
  `users_idusers` INT UNSIGNED NOT NULL ,
  `size` VARCHAR(45) NOT NULL ,
  `color` VARCHAR(45) NOT NULL ,
  `weight` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`users_idusers`) ,
  CONSTRAINT `fk_avatars_users`
    FOREIGN KEY (`users_idusers` )
    REFERENCES `mydb`.`users` (`idusers` ))
ENGINE = InnoDB;

Now, I'm not sure which is the best way which ensures a high performace level. 现在,我不确定哪种是确保高性能水平的最佳方法。

Should I implement relations in my programminglanguage and do a query on tables wich are relatet to my current dataset or should I implement the database in a way, which allows a mysql internal upate/delete Action 我应该在我的编程语言中实现关系并对与我当前数据集相关的表进行查询,还是应该以某种方式实现数据库,这允许mysql内部upate / delete Action

Thanks in advance. 提前致谢。

My suggestion would be to implement the constraints in your RDBMS. 我的建议是在你的RDBMS中实现约束。 It provides data integrity , better performance , less coding , and less chance of inconsistencies caused by the programmer. 它提供了数据完整性更好的性能更少的编码 ,以及程序员引起的不一致的可能性

我想把所有这些关系留给数据库...数据库中的关系比在代码中实现它更好...可靠,优化,性能更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 创建一个Laravel / PHP脚本,该脚本定期运行,例如每1周运行一次,以通过调用api更新我的MySQL数据库 - Create a Laravel / PHP script that runs periodically e.g. every 1 week to update my MySQL database with calls to an api 如何在PHP中循环$ num,例如1、2、3、4、1、2、3、4、1、2、3、4 - How to loop $num in php, e.g. 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, PHP中的“ @”符号,例如“ @ $ name [1]”吗? - '@' symbol in php, e.g. '@$name[1]'? 使MySQL查询动态化的最佳方法(例如,更新查询参数以显示上周) - Best method for making a MySQL query dynamic (e.g., update query parameters to show Previous Week) 如何从PHP PDO接收MYSQL警告(例如#1264超出范围) - How to receive MYSQL warnings (E.g. #1264 Out of Range) from PHP PDO 如何用php输出在mysql数据库中找到最大值(例如,唯一的用户ID) - How to find the highest value in mysql database with php output (e.g. unique user-ID) 获取用户国家代码(例如“ GB”)客户端(本地)PHP - Get User Country Code (e.g. 'GB') Client Side (locally) PHP PHP - 更改字符排序顺序,例如“a”>“{”= True - PHP - Changing character sort order so e.g. “a” > “{” = True PHP 函数将例如“æ”转换为“ae”,反之亦然? - PHP function that translates, e.g., "æ" into "ae" and vice versa? 在PHP中重用键名(例如,数组) - Reusing Key names (e.g. for arrays) in PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM