dqqy64515 2012-09-19 06:35
浏览 41
已采纳

如何在UserProfile和Location表之间创建关系?

I am trying to create a database with two tables: Location and UserProfile.

Location contains addresses, and UserProfile contains HowtownLocation and CurrentLocation.

I want Hometownlocation and Currentlocation to contain IDs from Location, and cascade when a user is deleted (assuming more than one user does not share the same address).

One user can have multiple addresses (i.e Hometown and Current), and one address can be used by many users.

I have a sort-of working version, but I still need it to cascade changes... and I want to be able to input data into it in PHPMyAdmin by creating a new UserProfile.

I am using MySQL Workbench, but that is not important.

:)

  • 写回答

1条回答 默认 最新

  • dongqiao2077 2012-09-19 06:40
    关注

    MySQL Reference helps. The Syntax is:

    [CONSTRAINT [symbol]] FOREIGN KEY
      [index_name] (index_col_name, ...)
      REFERENCES tbl_name (index_col_name,...)
      [ON DELETE reference_option]
      [ON UPDATE reference_option]
    
    reference_option:
      RESTRICT | CASCADE | SET NULL | NO ACTION
    

    Also make sure that your database is not MyISAM, but InnoDB which is the default in newer MySQL versions as far as i know.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题