SQL 表只有一行? [英] SQL table with a single row?

查看:60
本文介绍了SQL 表只有一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数据库中只有一行的表有什么意义(如果有)?

What is the point (if any) in having a table in a database with only one row?

注意:我不是在谈论表格中只有一行的可能性,而是当开发人员故意制作一个旨在始终只有一行的表格时.

Note: I'm not talking about the possibility of having only one row in a table, but when a developer deliberately makes a table that is intended to always have exactly one row.

销售税的例子是一个很好的例子.

The sales tax example is a good one.

我刚刚在一些代码中观察到我正在查看三个不同的表,这些表包含三种不同类型的证书(一种 SSL),每个表都只有一行.我不明白为什么不把它做成一张大桌子;我想我错过了什么.

I've just observed in some code I'm reviewing three different tables that contain three different kinds of certificates (a la SSL), each having exactly one row. I don't understand why this isn't made into one large table; I assume I'm missing something.

推荐答案

当开发人员被要求创建一个配置表来存储需要持久化而不经常更改的名称-值对数据时,我看到过这样的事情.他最终创建了一个单行表,每个配置变量都有一列.我不会说这是一个好主意,但我当然可以理解开发人员为什么按照他的指示这样做.不用说它没有通过审查.

I've seen something like this when a developer was asked to create a configuration table to store name-value pairs of data that needs to persist without being changed often. He ended up creating a one-row table with a column for each configuration variable. I wouldn't say it's a good idea, but I can certainly see why the developer did it given his instructions. Needless to say it didn't pass review.

我刚刚在一些代码中观察到我正在查看三个不同的表,这些表包含三种不同类型的证书(一种 SSL),每个表都只有一行.我不明白为什么不把它排成一排;我想我错过了什么.

I've just observed in some code I'm reviewing three different tables that contain three different kinds of certificates (a la SSL), each having exactly one row. I don't understand why this isn't made into one row; I assume I'm missing something.

这听起来不像是好的设计,除非有一些您不知道的重要细节.如果有三条信息具有相同的约束、相同的用途和相同的结构,它们应该存储在同一张表中,99% 的时间.这是表格的基本用途的重要组成部分.

This doesn't sound like good design, unless there are some important details you don't know about. If there are three pieces of information that have the same constraints, the same use and the same structure, they should be stored in the same table, 99% of the time. That's a big part of what tables are for fundamentally.

这篇关于SQL 表只有一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆