服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - 数据库技术 - 如何在MySQL表中定义一个列为主键,而不使用PRIMARY KEY关键字?

如何在MySQL表中定义一个列为主键,而不使用PRIMARY KEY关键字?

2023-08-23 12:01未知服务器之家 数据库技术

Example In this example, we have created a table Student123 by defining column RollNo with UNIQUE and NOT NULL constraints. Now, by describing the table we can see that RollNo is the PRIMARY KEY column. mysql Create table Student123(RollNo INT UNIQUE NOT

Example

In this example, we have created a table ‘Student123’ by defining column ‘RollNo’ with UNIQUE and NOT NULL constraints. Now, by describing the table we can see that ‘RollNo’ is the PRIMARY KEY column.

mysql> Create table Student123(RollNo INT UNIQUE NOT NULL, Name varchar(20));
Query OK, 0 rows affected (0.25 sec)

mysql> DESCRIBE Student123;

+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| RollNo | int(11)     | NO   | PRI | NULL    |       |
| Name   | varchar(20) | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+

2 rows in set (0.04 sec)

 

以上就是如何在MySQL表中定义一个列为主键,而不使用PRIMARY KEY关键字。

延伸 · 阅读

精彩推荐