简体   繁体   English

如何为用户配置文件页面设计数据库架构

[英]How do you design a database schema for a user profile page

Trying to set up a user profile page for a job site. 尝试为作业站点设置用户个人资料页面。 The database I plan to use is the MySQL database. 我计划使用的数据库是MySQL数据库。

Looking into a few database design I came up with this schema. 通过研究一些数据库设计,我想到了这种模式。

First, the user management tables 一,用户管理表

CREATE TABLE `user` (
  `user_id` int(11) NOT NULL,
  `firstname` varchar(32) NOT NULL,
  `lastname` varchar(32) NOT NULL,
  `email` varchar(96) NOT NULL,
  `mobile_number` varchar(32) NOT NULL,
  `password` varchar(40) NOT NULL,
  `salt` varchar(9) NOT NULL,
  `address_id` int(11) NOT NULL DEFAULT '0',
  `ip` varchar(40) NOT NULL,
  `status` tinyint(1) NOT NULL,
  `approved` tinyint(1) NOT NULL,
  `registration_date` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `user_address` (
  `user_id` int(11) NOT NULL,
  `city` varchar(128) NOT NULL
  `work_city` varchar(128) NOT NULL,
  `postal_code` varchar(10) NOT NULL,
  `country_id` int(11) NOT NULL DEFAULT '0'
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

CREATE TABLE `user_description` (
  `user_id` int(11) NOT NULL,
  `description` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

and then the education table and work experience 然后是教育桌和工作经验

CREATE TABLE `education_detail` (
  `user_id` int(11) NOT NULL,
  `certificate_degree_name` varchar(255) DEFAULT NULL,
  `major` varchar(255) DEFAULT NULL,
  `institute_university_name` varchar(255) DEFAULT NULL,
  `start_date` date NOT NULL DEFAULT '0000-00-00',
  `completion_date` date NOT NULL DEFAULT '0000-00-00'
)

CREATE TABLE `experience_detail` (
  `user_id` int(11) NOT NULL,
  `is_current_job` int(2) DEFAULT NULL,
  `start_date` date NOT NULL DEFAULT '0000-00-00',
  `end_date` date NOT NULL DEFAULT '0000-00-00',
  `job_title` varchar(255) DEFAULT NULL,
  `company_name` varchar(255) DEFAULT NULL,
  `job_location_city` varchar(255) DEFAULT NULL,
  `job_location_state` varchar(255) DEFAULT NULL,
  `job_location_country` varchar(255) DEFAULT NULL,
  `job_description` varchar(255) DEFAULT NULL
)

Note that user_id in table user_address, user_description, education_detail and experience_detail is a foreign key referencing it to the table user. 请注意,表user_address,user_description,education_detailexperience_detail中的user_id是将其引用给表user的外键。

There are a few more table like skills, certification etc to which I plan on using user_id as a FK. 我计划使用user_id作为FK,还有一些其他表格,例如技能,认证等。

My question, is this database design good enough? 我的问题是,这个数据库设计够好吗? Can you suggest me what should be done more to make the design much better? 您能建议我做些什么以使设计更好吗?

Keep in mind not all will have work experience, some may be freshers. 请记住,并非所有人都有工作经验,有些人可能更新鲜。

Use InnoDB, not MyISAM. 使用InnoDB,而不是MyISAM。 (There are many Q&A explaining 'why'.) (有很多问答解释“为什么”。)

NULL or an empty string is perfectly fine for a missing description . NULL或空字符串对于缺少description是很好的选择。 Do you have any further argument for disliking such? 您还有其他理由不喜欢这种说法吗? (Meanwhile, InnoDB is more efficient at handling optional big strings.) (同时,InnoDB在处理可选的大字符串方面效率更高。)

Every table should have a PRIMARY KEY ; 每个表应该有一个PRIMARY KEY ; you don't seem to have any. 您似乎没有。 The first table probably needs user_id as the PK. 第一个表可能需要user_id作为PK。 Read about AUTO_INCREMENT . 了解有关AUTO_INCREMENT

As with description , why is address in a separate table? description ,为什么address在单独的表中?

May I suggest this for country name/code/id: 我可以为国家名称/代码/ ID建议以下内容:

country_code CHAR(2) CHARACTER SET ascii

Education is 1:many from users, so user_id cannot be the PK. 教育程度为1:1,来自用户很多,因此user_id不能为PK。 Ditto for jobs. 同上工作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM