大表的问题(没有可用的主键) [英] Issue with the big tables ( no primary key available)

查看:44
本文介绍了大表的问题(没有可用的主键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Tabe1 有大约 10 个缺乏记录(100 万)并且不包含任何主键.使用 SELECT 命令(使用特定的 WHERE 条件)检索数据需要大量时间.我们是否可以通过向表中添加主键来减少检索时间,或者我们是否需要遵循任何其他方式来做同样的事情.请帮助我.

Tabe1 has around 10 Lack records (1 Million) and does not contain any primary key. Retrieving the data by using SELECT command ( With a specific WHERE condition) is taking large amount of time. Can we reduce the time of retrieval by adding a primary key to the table or do we need to follow any other ways to do the same. Kindly help me.

推荐答案

主键对性能没有直接影响.但间接地,确实如此.这是因为当您向表添加主键时,SQL Server 会创建一个唯一索引(默认情况下是聚集索引),用于强制执行实体完整性.但是您可以在表上创建自己的唯一索引.所以,严格来说,主索引不会影响性能,但主键使用的索引会.

A primary key does not have a direct affect on performance. But indirectly, it does. This is because when you add a primary key to a table, SQL Server creates a unique index (clustered by default) that is used to enforce entity integrity. But you can create your own unique indexes on a table. So, strictly speaking, a primary index does not affect performance, but the index used by the primary key does.

什么时候应该使用主键?

这篇关于大表的问题(没有可用的主键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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