是的,您可以使用以下语法。以下是语法-
PRIMARY KEY(yourColumnName1,yourColumnName2);
让我们首先创建一个表-
mysql> create table DemoTable -> ( -> StudentFirstName varchar(100), -> StudentLastName varchar(100), -> StudentAge int, -> StudentCountryName varchar(100), -> PRIMARY KEY(StudentFirstName,StudentLastName) -> );
让我们检查表的描述-
mysql> desc DemoTable;
输出结果
这将产生以下输出-
+--------------------+--------------+------+-----+---------+-------+ | 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)