Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Can we use PRIMARY KEY( column1, column2) in MySQL to make pairs?
Yes, you can use below syntax. Following is the syntax −
PRIMARY KEY(yourColumnName1,yourColumnName2);
Let us first create a table −
mysql> create table DemoTable -> ( -> StudentFirstName varchar(100), -> StudentLastName varchar(100), -> StudentAge int, -> StudentCountryName varchar(100), -> PRIMARY KEY(StudentFirstName,StudentLastName) -> ); Query OK, 0 rows affected (0.74 sec)
Let us check the description of the table −
mysql> desc DemoTable;
Output
This will produce the following output −
+--------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | StudentFirstName | varchar(100) | NO | PRI | NULL | | | StudentLastName | varchar(100) | NO | PRI | NULL | | | StudentAge | int(11) | YES | | NULL | | | StudentCountryName | varchar(100) | YES | | NULL | | +--------------------+--------------+------+-----+---------+-------+ 4 rows in set (0.00 sec)
Advertisements
