- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
To Continue Learning Please Login
Login with Google