SQL Server 15 – Composite Key



An interesting thing you can do with primary keys is that you can make a combination of columns the primary key. This is important when more than one column is required to make something unique. In an intermediary table, instead of having an association ID, we can have the combination of two rows as the primary key. This is known as either a compound or composite primary key.

Nhà cái Fi88 tặng thêm 100% cho lần gửi tiền đầu tiên lên đến 2 triệu đồng!
👉 Nạp lại mỗi ngày lên đến 5% siêu hấp dẫn lên tới 6000k!

In the situation of using natural keys, composite keys are more common. For example, you could have a shopping website that allows multiple people from the same household to use a certain coupon you sent out. In this situation, you could use the address and the person’s name as the natural primary key.

What is the difference between a primary key and a column that has UNIQUE and NOT NULL constraints? The primary difference has to do with indexing.

When you create a primary key, the column will automatically be indexed. This means that working with this data is faster. Now, we haven’t talked a ton on indexes, but by default this will create a clustered index. UNIQUE constraints are also indexed by default, but the default index for a UNIQUE constraint is a non-clustered index. Clustered indexes determine how the table is actually stored, while non clustered indexes will make a sorted list that has reference to the data. This is not a life changing difference because these can actually be changed. We will discuss all of the details of indexing in future videos. As a side note, the IDENTITY column is not automatically indexed.

How do we reference primary keys? This requires what is known as a foreign key, which we will discuss in the next video.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Support me!

Subscribe to my newsletter:

Donate!:

~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~

More content:
Facebook:
Google+:
Twitter:

Nhà cái Fi88 tặng thêm 100% cho lần gửi tiền đầu tiên lên đến 2 triệu đồng!
👉 Nạp lại mỗi ngày lên đến 5% siêu hấp dẫn lên tới 6000k!

Amazing Web Hosting – (The best web hosting for a cheap price!)

sql server, composite, key, composite key, primary, unique, intermediary, table, compound, not null, indexed, reference, foreign, caleb, curry, calebthevideomaker2

Xem Thêm Bài Viết Công Nghệ Khác: https://missionreadyat-6.com/cong-nghe

Nguồn: https://missionreadyat-6.com/

Leave a Reply