首页 \ 问答 \ @“”的替代品?(Alternatives to @“”? [duplicate])

@“”的替代品?(Alternatives to @“”? [duplicate])

这个问题在这里已有答案:

我有一个字符串,里面有多个" in,里面写着@""当然,xcode认为这是我结束@" 。 有什么替代品我可以用于@""做同样的事情吗?


This question already has an answer here:

I have a string that has multiple " in it, which is written inside of @"" and of course, xcode sees this as me ending the @". Is there any alternatives I can use for @"" that would do the same thing?


原文:https://stackoverflow.com/questions/14828521
更新时间:2022-04-26 18:04

最满意答案

您必须区分主键代理键 。 自动递增列将是后者的特例。 因此,你的问题是双重的:

  1. 每个表都需要有主键吗?
  2. 每个表是否需要有代理主键?

第一个问题的答案是YES,除了在一些特殊情况下(多对多关系的关联表可以被认为是这种特殊情况的一个例子)。 原因是你通常需要能够(如果不是现在,那么将来)能够始终如一地处理该表的各个行 - 例如用于更新/删除。

第二个问题的答案是NO 。 如果你的表代表一个核心商业实体,那么它可以从多对一的关联中引用,使用代理关键字可能是一个好主意; 但并非绝对必要。

有点不清楚你的桌子的功能是什么; 从你的描述中,它听起来像是它具有“值的集合”语义(FK到“主”表+值)。 在这种情况下,某些ORM不支持代理键; 如果这是什么引发了你的问题,那么离开代理人(或者甚至是包中的主要人员)钥匙是可以的。


You have to distinguish between primary key and surrogate key. Auto-incremented column would be a particular case of the latter. Your question, therefore, is twofold:

  1. Does every table need to have a primary key?
  2. Does every table need to have a surrogate primary key?

The answer to first question is YES except in some special cases (association table for many-to-many relationship arguably being an example of such a special case). The reason for this is that you usually need to be able (if not right now then in the future) to consistently address individual rows of that table - for updates / deletion, for example.

The answer to the second question is NO. If your table represents a core business entity then OR it can be referenced from many-to-one association, having a surrogate key is probably a good idea; but it's not absolutely necessary.

It's somewhat unclear what your table's function is; from your description it sounds like it has "collection of values" semantics (FK to "main" table + value). Certain ORMs don't support surrogate keys in such circumstances; if that's what has prompted your question it's OK to leave the surrogate (or even primary in case of bag) key off.

相关问答

更多
  • 来自http://www.sqlite.org/lang_altertable.html的引用 新列可以采用CREATE TABLE语句中允许的任何形式,但具有以下限制: 该列可能没有PRIMARY KEY或UNIQUE约束。 The quote from http://www.sqlite.org/lang_altertable.html The new column may take any of the forms permissible in a CREATE TABLE statement, wi ...
  • 创建后,您无法以任何重要的方式修改SQLite表。 接受的建议解决方案是创建具有正确要求的新表,并将数据复制到其中,然后删除旧表。 这里是关于这个的官方文档: http : //sqlite.org/faq.html#q11 You can't modify SQLite tables in any significant way after they have been created. The accepted suggested solution is to create a new table wi ...
  • 从纯技术角度来看,唯一索引与主键具有完全相同的效果。 (在SQLite中,一些主键允许NULL以实现向后兼容。) 唯一的区别是主键约束没有出现在表定义本身中,这对于文档来说可能是一件坏事。 另请参阅SQLite中的CREATE UNIQUE INDEX或INTEGER PRIMARY KEY更高性能 。 From a purely technical point of view, an unique index has exactly the same effect as a primary key. (I ...
  • 您必须区分主键和代理键 。 自动递增列将是后者的特例。 因此,你的问题是双重的: 每个表都需要有主键吗? 每个表是否需要有代理主键? 第一个问题的答案是YES,除了在一些特殊情况下(多对多关系的关联表可以被认为是这种特殊情况的一个例子)。 原因是你通常需要能够(如果不是现在,那么将来)能够始终如一地处理该表的各个行 - 例如用于更新/删除。 第二个问题的答案是NO 。 如果你的表代表一个核心商业实体,那么它可以从多对一的关联中引用,使用代理关键字可能是一个好主意; 但并非绝对必要。 有点不清楚你的桌子的功能 ...
  • 我应该在所有三列(userid, set, and key)上创建一个主键(userid, set, and key) 做这个。 使用代理主键会产生一个不用于其他目的的额外列。 与代理主键一起创建UNIQUE INDEX与创建非集群PRIMARY KEY ,并且会导致额外的KEY lookup ,这对性能来说更糟糕。 创建没有PRIMARY KEY的UNIQUE INDEX将导致HEAP-organized表,这将需要额外的RID lookup来访问值:也不是很好。 Should I create a pr ...
  • 尝试这个: ALTER TABLE myTable ADD id INT IDENTITY CONSTRAINT id _pk PRIMARY KEY; Try this: ALTER TABLE myTable ADD id INT IDENTITY CONSTRAINT id _pk PRIMARY KEY;
  • 在数据库上使用: DBCC CHECKIDENT(表,RESEED,1) 右键单击表,然后选择“新建查询”并在此处运行此命令。 use on database: DBCC CHECKIDENT(TABLE, RESEED,1) Right click over table, and select New Query and run this command here.
  • 当然 - 您可以在CREATE TABLE语句中定义PRIMARY KEY约束。 这将生成默认的PRIMARY KEY CREATE TABLE dbo.Table (ID INT IDENTITY PRIMARY KEY, .......) 但你也可以完全定义约束的名称: CREATE TABLE dbo.Table2 (ID INT IDENTITY CONSTRAINT PK_Table2 PRIMARY KEY, ......) Sure - you can define ...
  • 一般来说,你不应该编辑主键。 SQL Server中的主键通常具有一个集群唯一索引,因此编辑主键意味着您可能不得不重建索引(可能不是每次都是,但取决于偏移)。 相反,我会创建一个假主键,如SQL Server中的IDENTITY列,并在名称列上放置一个UNIQUE约束。 如果您的表增长很大,则检索int列上的项目也会比在varchar()列上检索项目更快。 更新:由于我被告知我没有回答问题(即使这是可接受的答案),但可以更改SQL Server中的主键值。 但它在技术上并不是编辑操作,因为引用完整性可能会阻 ...
  • 这是一个主观问题,所以我希望你不要介意我回答一些意见:) 在我所做的绝大多数表格中 - 我说的是95%+ - 我已经添加了一个主键,并且很高兴我做到了。 这可能是我表中最关键的唯一字段(想想“社会安全号码”),或者通常只是一个自动递增的数字,它允许我在查询时快速轻松地引用字段。 后一种用法是最常见的,它甚至有自己的名称:“代理”或“合成”键。 这是由数据库自动生成的值,而不是从应用程序数据派生的值。 如果要在表之间添加关系,则此代理键可立即用作外键。 正如其他人回答的那样,这些密钥非常常见,即使你不这样做, ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)