Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 是否修改语句中未指定的列重置属性?_Sql_Mariadb_Alter - Fatal编程技术网

Sql 是否修改语句中未指定的列重置属性?

Sql 是否修改语句中未指定的列重置属性?,sql,mariadb,alter,Sql,Mariadb,Alter,MODIFY列语句是否会丢弃MariaDB中未指定的属性 例如:。;考虑下表和语句,执行语句后是否会保留默认值 t +-------+---------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | c | int(11) | NO | PRI | 5

MODIFY列
语句是否会丢弃MariaDB中未指定的属性

例如:。;考虑下表和语句,执行语句后是否会保留默认值

t
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| c     | int(11) | NO   | PRI | 5       |       |
+-------+---------+------+-----+---------+-------+
文件在我看来有点不清楚

允许您修改列的类型。该列将与原始列位于同一位置,列上的所有索引都将保留。请注意,在修改列时,应为新列指定所有属性


这是否意味着应指定所有属性或将丢失所有属性?

默认属性将丢失

MariaDB [test]> DESC test_table;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| column_a | int(11) | NO   | PRI | 5       |       |
+----------+---------+------+-----+---------+-------+
1 row in set (0.002 sec)

MariaDB [test]> ALTER TABLE test_table
    -> MODIFY COLUMN column_a INT(11) NULL;
Query OK, 0 rows affected (0.007 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [test]> DESC test_table;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| column_a | int(11) | NO   | PRI | NULL    |       |
+----------+---------+------+-----+---------+-------+
1 row in set (0.000 sec)
根据文档,您需要指定所有属性,在您的示例中,您没有明确指定默认值。比较:

MariaDB [test]> ALTER TABLE test_table
    -> MODIFY COLUMN column_a INT(11) NULL DEFAULT 5;
Query OK, 0 rows affected (0.007 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [test]> DESC test_table;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| column_a | int(11) | NO   | PRI | 5       |       |
+----------+---------+------+-----+---------+-------+
1 row in set (0.001 sec)

希望这有帮助。

默认属性将丢失

MariaDB [test]> DESC test_table;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| column_a | int(11) | NO   | PRI | 5       |       |
+----------+---------+------+-----+---------+-------+
1 row in set (0.002 sec)

MariaDB [test]> ALTER TABLE test_table
    -> MODIFY COLUMN column_a INT(11) NULL;
Query OK, 0 rows affected (0.007 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [test]> DESC test_table;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| column_a | int(11) | NO   | PRI | NULL    |       |
+----------+---------+------+-----+---------+-------+
1 row in set (0.000 sec)
根据文档,您需要指定所有属性,在您的示例中,您没有明确指定默认值。比较:

MariaDB [test]> ALTER TABLE test_table
    -> MODIFY COLUMN column_a INT(11) NULL DEFAULT 5;
Query OK, 0 rows affected (0.007 sec)
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [test]> DESC test_table;
+----------+---------+------+-----+---------+-------+
| Field    | Type    | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+-------+
| column_a | int(11) | NO   | PRI | 5       |       |
+----------+---------+------+-----+---------+-------+
1 row in set (0.001 sec)

希望这能有所帮助。

是的,我知道某些属性(例如:
DEFAULT
)可能会丢失,请参阅。是的,我知道某些属性(例如:
DEFAULT
)可能会丢失,请参阅。您是否将
列a
定义为主键?如果是这样,并且希望将该列从
notnull
修改为
NULL
,则该属性不会更改。@wchiquito。主键不能是
NULL
,因此您评论中的问题没有意义。@GordonLinoff:我评论中的问题是如何确定列
c
(原始问题)是主键,因为我们试图将此列从
非NULL
修改为
NULL
,这似乎表明它不是主键。@wchiquito:这是真的,主键不能为NULL,因此这不会改变,但最初的问题似乎是,当不是所有属性都明确声明时,通过更改查询是否会丢失任何其他属性。很好,理解。谢谢您的评论。您是否已将
列a
定义为主键?如果是这样,并且希望将该列从
notnull
修改为
NULL
,则该属性不会更改。@wchiquito。主键不能是
NULL
,因此您评论中的问题没有意义。@GordonLinoff:我评论中的问题是如何确定列
c
(原始问题)是主键,因为我们试图将此列从
非NULL
修改为
NULL
,这似乎表明它不是主键。@wchiquito:这是真的,主键不能为NULL,因此这不会改变,但最初的问题似乎是,当不是所有属性都明确声明时,通过更改查询是否会丢失任何其他属性。很好,理解。谢谢你的评论。