【发布时间】:2019-05-31 10:05:36
【问题描述】:
将表的所有列存储在单个 JSON 列中的缺点是什么?
例如对于用户表而不是这个
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('firstname');
$table->string('lastname');
$table->string('username')->unique();
$table->string('email')->unique();
$table->string('password');
$table->timestamps();
$table->rememberToken();
});
就这样做
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->json('attributes'); // contains all the fields
$table->timestamps();
$table->rememberToken();
});
更新
简而言之,这种方法不适用于具有自定义属性的产品。 NoSql 数据库是电子商务网站/系统的最佳选择。
但 JSON 字段可用于组合较少使用的字段,如性别、年龄、地址。
真的吗?
【问题讨论】:
-
希望我的结论是正确的。对所有字段使用 JSON 会增加额外的数据层和工作量。此外,这就像将 SQL 用于其他目的一样,因此如果所有字段都替换为 JSON,则最好使用 NoSQL 数据库。归根结底,这完全取决于我们应该选择哪种数据库类型的业务需求。
-
可以查询JSON,JSON函数很多,缺点是非结构化,所以可能和schemaless数据库一样缺点。 mariadb.com/resources/blog/json-with-mariadb-10-2