Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 查找表本地化_Sql_Sql Server - Fatal编程技术网

Sql 查找表本地化

Sql 查找表本地化,sql,sql-server,Sql,Sql Server,在我使用本地化的项目中,我有以下表格: create table dbo.Posts ( Id int identity not null primary key clustered (Id), Created datetime not null, ); create table dbo.PostsLocalized ( Id int identity not null primary key clustered (Id), PostId int not null, Lan

在我使用本地化的项目中,我有以下表格:

create table dbo.Posts
(
  Id int identity not null primary key clustered (Id),
  Created datetime not null,
);

create table dbo.PostsLocalized
(
  Id int identity not null primary key clustered (Id),
  PostId int not null,
  LanguageId int not null,
  PostTypeId int not null,
  [Text] nvarchar (max) not null,
  Title nvarchar (120) not null,
        constraint UQ_PostsLocalized_PostId_LanguageId unique (PostId, LanguageId)  
);

create table dbo.PostTypes
(
  Id int identity not null primary key clustered (Id),
  Name nvarchar (max) not null
);
因此,我使用PostsLocalized表(而不是PostTypes表)对帖子进行本地化

PostTypes表基本上是一个查找表,与我数据库中的其他表一样

您认为我应该本地化查找表,例如PostType吗

我将添加一个名为PostTypesLocalized的新表,该表使用本地化名称进行了本地化

其他查找表(如性别、国家等)也是如此

还是应该只在应用程序中本地化查找表

更新

澄清:

  • 一篇文章的所有本地化版本都具有相同的PostType

  • 我需要在UI中显示PostType,这就是我需要翻译它们的原因

  • 因此,我尝试了一种新方法,遵循@dasblinkenlight的答案:

    create table dbo.Posts
    (
      Id int identity not null primary key clustered (Id), -- The id of the localized post
      Created datetime not null,
      PostId int not null, -- The id of the post
      PostTypeId int not null
      LanguageId int not null,
      [Text] nvarchar (max) not null,
      Title nvarchar (120) not null,
            constraint UQ_PostsLocalized_PostId_LanguageId unique (PostId, LanguageId)  
    );
    
    create table dbo.PostTypes
    (
      Id int identity not null primary key clustered (Id), -- PostType localized id
      PostTypeId int not null, -- The id of the post type
      Name nvarchar (max) not null
    );
    
    考虑(1)那么Posts>PostTypeId应该与PostTypes>PostTypeId相关。


    但是我该怎么做呢?

    答案取决于
    PostTypes
    表的
    Name
    字段的用法:

    • 如果该字段的所有用途都来自您可能拥有的代码和/或不可本地化的脚本,则不需要本地化
    • 如果
      名称
      进入最终用户的视图,则应将表本地化
    如果您需要本地化
    PostTypes
    ,除了具有独立于区域设置的名称的
    PostTypes
    表之外,还有一个单独的
    PostTypesLocalized
    表,听起来是一个合适的解决方案

    <>你应该考虑<代码> PyType ID>代码>字段。所有具有相同
    PostId
    的本地化是指相同的
    PostTypeId
    ,还是其中一些不同?如果相同的
    Post
    的所有本地化引用相同的
    PostType
    ,则该字段应属于
    Posts
    表,而不是
    PostLocalized

    我应该只在应用程序中本地化查找表吗


    将本地化添加到数据库将被视为应用程序的本地化。当您考虑使用同一数据库结构的多个应用程序时,这是一个很好的解决方案。

    我还建议您对主键使用有意义的名称,而不是ID。简单ID是不明确的,会迫使您根据列所在的表更改列的名称。随着系统变得越来越大,处理这件事真的很痛苦。给他们一个有意义的名字并保持一致。@SeanLange,对不起,在哪个表中?所有的。例如,在POST中有一个名为ID的列,该列在其他表中成为POST ID。只需在每个表中列出它的名称即可。和你的其他钥匙一样。我明白了,但是看到我的代码更新了。。。那会很奇怪,我不同意。在每个表中命名主键ID都很奇怪,尤其是在其他表中必须更改该列的名称时。我只是提供了一个关于命名约定的建议,以便从长远来看对您有所帮助。您必须在列上包含注释以解释它们的来源,这一事实清楚地说明了为什么您应该在所有表中为同一数据段使用一个列名。请随意忽略我的评论。:)我刚刚更新了我的代码。。。我还有一个问题。您认为我应该怎么做?@MDMoura由于同一帖子的所有本地化都将具有相同的
    PostType
    ,因此您的
    post
    表应该具有
    PostTypeId
    字段:
    创建表dbo.Posts(Id int-identity-not-null主键集群(Id),Created-datetime-not-null,PostTypeId-not-null)
    。语言ID、文本和标题应属于
    后本地化
    ,即您在原始结构中使用的方式。您应该使用特定于语言的名称创建
    PostTypeLocalized
    ,参考
    PostType
    。因此,您的意思是不可能将同一PostType关联到所有翻译,并且只使用我在更新中添加的一个Posts表?@MDMoura当然可以。不过,我认为这是次优的。更新后的
    Posts
    表看起来像是对原始
    PostLocalized
    表的修改,因为它有一个语言ID text,等等。您最初的想法是将不可本地化字段保留在
    Posts
    中,并将可本地化字段保留在
    postscalized
    中,这样可以更好地区分表示数据核心的内容(即
    Posts
    )和仅用于本地化的数据(即
    postscalized
    ).出于好奇,您将如何使用我的表的第二个版本设置该关系?