gpt4 book ai didi

mysql - 在 MySQL 中重新创建 UNI 和 MUL 索引

转载 作者:行者123 更新时间:2023-11-29 21:55:54 28 4
gpt4 key购买 nike

我正在做一个不同的 MySQL,以帮助将我的表从开发更新到生产,但我在索引方面遇到了一些问题。

我使用显示表中的完整列来获取表的索引/键并进行比较,然后构建必要的查询来更新第一个表。

我得到了主键,这有效。但我一直在阅读,但我仍然没有完全理解其他两种可能性,MULUNI

我阅读了手册页..

If Key is PRI, the column is a PRIMARY KEY or is one of the columns in a multiple-column PRIMARY KEY.

If Key is UNI, the column is the first column of a unique-valued index that cannot contain NULL values.

If Key is MUL, multiple occurrences of a given value are permitted within the column. The column is the first column of a nonunique index or a unique-valued index that can contain NULL values.

这是我目前所掌握的内容,如果它有某种相关性的话。

        if($key1 != $key2){
if($key1['PRI'] != $key2['PRI']){
// remove any existing primary keys
$results[$table_name][] = "ALTER TABLE $table_name DROP PRIMARY KEY;";
// add the new primary keys
$results[$table_name][] = "ALTER TABLE $table_name ADD CONSTRAINT pk_$table_name PRIMARY KEY (".implode(",", $key2['PRI']).")";
}
if($key1['MUL'] != $key2['MUL']){
// what to do here?
}
if($key1['UNI'] != $key2['UNI']){
// what to do here?
}
}

我猜我可以为UNI做这样的事情:ALTER TABLE 表
添加约束 uc_myKey UNIQUE (indexColumn)
..正确吗?

MUL三键怎么样?其语法是什么?

创建 MULUNI 类型键的 MySQL 语法是什么?

谢谢。

最佳答案

呃...

                    switch($type){
case "PRI":
$ret[] = $add ?
"ALTER TABLE `$tbl` ADD PRIMARY KEY(`$col`);" :
"ALTER TABLE `$tbl` DROP PRIMARY KEY;" ;
break;
case "MUL":
$ret[] = $add ?
"ALTER TABLE `$tbl` ADD UNIQUE (`$col`);" :
"ALTER TABLE `$tbl` DROP INDEX `$col`;" ;
break;
case "UNI":
$ret[] = $add ?
"ALTER TABLE `$tbl` ADD INDEX (`$col`);" :
"ALTER TABLE `$tbl` DROP INDEX `$col`;" ;
break;
}

关于mysql - 在 MySQL 中重新创建 UNI 和 MUL 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33161535/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com