Home >Database >Mysql Tutorial >How to Create a Composite Primary Key in SQL Server 2008?
Creating Composite Primary Keys in SQL Server 2008
A composite primary key is a unique combination of two or more columns that identifies each row of a table. This ensures that each row in the table is distinct. Creating a composite primary key in SQL Server 2008 is a straightforward process.
To create a composite primary key, follow these steps:
column_a integer not null, column_b integer not null,
primary key (column_a, column_b)
This creates a primary key consisting of the column_a and column_b columns. Each combination of values in these columns must be unique for each row in the table.
Example:
Let's create a table named my_table with a composite primary key consisting of the column_a and column_b columns:
create table my_table ( column_a integer not null, column_b integer not null, column_c varchar(50), primary key (column_a, column_b) );
Now, each row in the my_table table will be uniquely identified by the combination of column_a and column_b.
The above is the detailed content of How to Create a Composite Primary Key in SQL Server 2008?. For more information, please follow other related articles on the PHP Chinese website!