找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 mysql教程 查看内容

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

作者:模板之家 2023-8-21 14:25 111人关注

AsweknowthataPRIMARYKEYcolumnmusthaveuniquevaluesandcannothavenullvalueshenceifwewilldefineacolumnwithUNIQUEandNOTNULLconstraintboththenthatcolumnwouldbecomePRIMARYKEYcolumn.ExampleInthisexample,wehav ...

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

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)
登录后复制


路过

雷人

握手

鲜花

鸡蛋
原作者: 网络收集 来自: 网络收集

全部回复(0)