

Defining memberreportID as PK in your MemeberReport table, will ensure uniqueness of the ID in that table. I guess a given memberreportID will appear once in the MemberReport table, but can appear multiple times in other tables. This column becomes a foreign key in the second table. In a foreign key reference, a link is created between two tables when the column or columns that hold the primary key value for one table are referenced by the column or columns in another table. If a primary key constraint is defined on more than one column, values may be duplicated within one column, but each combination of values from all the columns in the primary key constraint definition must be unique.Ī foreign key (FK) is a column or combination of columns that is used to establish and enforce a link between the data in two tables to control the data that can be stored in the foreign key table.

This index also permits fast access to data when the primary key is used in queries. When you specify a primary key constraint for a table, the Database Engine enforces data uniqueness by automatically creating a unique index for the primary key columns. Because primary key constraints guarantee unique data, they are frequently defined on an identity column. This column, or columns, is called the primary key (PK) of the table and enforces the entity integrity of the table. These are important database objects.Ī table typically has a column or combination of columns that contain values that uniquely identify each row in the table. Primary keys and foreign keys are two types of constraints that can be used to enforce data integrity in SQL Server tables.
Sql define primar ykey how to#
Hence I would like to ask if I can use my foreign key as a primary key for all my other tables and how to do so? However, in my opinion, memberreportID can basically be used as a unique key (primary key) for all the 5 tables that I have.Īll my 5 tables require memberreportID as their foreign key. Maybe something like an ID (Unique value). My adminassign table has memberreportID as a foreign key and after much research, I realized that almost all of them mentioned that it is a must for a table to have a primary key.

My memberreport table has a primary key called memberreportID which I can very much use it as a universal primary key for all my 5 tables in my database. Unfortunately, some of my tables doesn't seems to require a primary key as my foreign key is sufficient as a unique key. After researching, it seems like all talbe must have a unique primary key to identify the rows. I'm using SQL Server 2008 for my web application developed with VS 2012.Ĭurrently, this is how my database is being designed. How do I make a foreign key as a primary key for my table?
