首页 \ 问答 \ 你需要在MySQL中设置外键吗?(Do you need to set foreign keys in MySQL?)

你需要在MySQL中设置外键吗?(Do you need to set foreign keys in MySQL?)

假设你在MySQL数据库中有两个如下所示的表:

TABLE人物:

  primary key: PERSON_ID,
  NAME,
  SURNAME, etc.

TABLE地址:

  primary key: ADDRESS_ID,
  foreign key: PERSON_ID,
  addressLine1, etc.

如果您管理行的创建(在这两个表中)以及通过PHP检索数据,您是否还需要在数据库中创建物理关系? 如果是,为什么?


Let's say you have got two tables like the following in a MySQL database:

TABLE people:

  primary key: PERSON_ID,
  NAME,
  SURNAME, etc.

TABLE addresses:

  primary key: ADDRESS_ID,
  foreign key: PERSON_ID,
  addressLine1, etc.

If you manage the creation of rows (in both table) and the retrieving of data trough PHP do you still need to create a physical relationship in the database? If yes, why?


原文:https://stackoverflow.com/questions/13086160
更新时间:2023-02-09 08:02

最满意答案

宏的范围(在预处理器内)是从其定义点到相应的#undef或翻译单元的末尾。 预处理器对代码中的函数或其他结构一无所知。


The scope (within the pre-processor) of a macro is from its definition point to either a corresponding #undef or the end of the translation unit. The pre-processor does not know anything about functions or other structures in the code.

相关问答

更多
  • 你很近。 鉴于你的'Zf2NVIApp.js'文件包含 define(['angular'], function(angular){ return angular.module('Zf2NVIApp', []); }); 比你只需要返回你的指令AMD模块定义中的值,它应该工作: define(['Zf2NVIApp'], function (Zf2NVIApp) { 'use strict'; Zf2NVIApp.directive('locationBtn', function() { ...
  • 您必须将sayHi函数传递给您的指令。 指令创建他们自己的范围,所以说HH函数不是你的指令范围的一部分,允许它的方式是通过创建一个新的道具来传递它。 HTML
    JS var ...
  • 错误是您没有将tabs函数传递给angular的指令方法。 看到参数不匹配: define(["angular","./controller","./tabs","./pane"],function(tabsController,tabs,pane){ 相反: define(["angular","./controller","./tabs","./pane"],function(angular, tabsController, tabs, pane){ The error is that you ar ...
  • 指令名称和绑定/范围配置必须符合规范化约定。 这意味着指令的正确定义应该是: angular.module(MODULE_NAME).directive('logDir', logDirDirective); 对于绑定配置也一样: bindToController: { val: '=logDir' }, 检查“AngularJs指令命名约定”问题以获取更详细的原因。 UPD。 以下是使用@和=绑定的变体演示: http : //plnkr.co/edit/mA0YnVhd7t241kdAvgR ...
  • 正如@tymeJV所说,你需要先编译html,然后在指令控制器中调用button() var app = angular.module("myApp", []); app.directive('aaaa', function($compile) { return { restrict: 'E', scope: { data: '=', //this is not working: button: function(){console.log('hello fro ...
  • 在分配$scope.random之前调用getByteLen 。 改为使用它: $scope.random = function(value) { $scope.dynamic = value; $scope.downloadPercentage = parseFloat((value / $scope.maxBytes) * 100).toFixed(0); console.log('current value-dyn ...
  • 宏的范围(在预处理器内)是从其定义点到相应的#undef或翻译单元的末尾。 预处理器对代码中的函数或其他结构一无所知。 The scope (within the pre-processor) of a macro is from its definition point to either a corresponding #undef or the end of the translation unit. The pre-processor does not know anything about fun ...
  • 从文档 : 范围:指令用于注册手表的范围 。 您也可能有兴趣查看$范围和范围之间的差异。 所有指令都有一个与它们相关的范围。 他们使用这个范围来访问模板和链接函数中的数据/方法。 默认情况下,除非明确设置,否则指令不会创建自己的范围。 因此,指令使用它们的父作用域(通常是控制器)作为它们自己的作用域。 但是,AngularJS允许我们通过传递称为指令定义对象的配置对象来更改指令的默认范围。 一个指令定义对象 - 我们称之为DDO--是一个简单的JavaScript对象,用于配置指令的行为,如template ...
  • 我自己找到了答案。 通过将“scope:true”添加到父指令(我将原始问题改为包含此编辑),它创建了一个子范围,它将原型继承自其父级,从而创建我正在寻找的功能。 如果有人有更好的方法,我会全力以赴。 I found the answer myself. By adding "scope: true" to the parent directive (I changed my original question to include this edit), it creates a child scope ...
  • 它不起作用,因为你在不同的范围使用2个指令, ngClick和myScopedDirective 。 您需要为您的指令创建一个模板并调用click函数,如下所示: