MySQL
 Computer >> コンピューター >  >> プログラミング >> MySQL

MySQLテーブルからインデックスを削除します


MySQLテーブルからインデックスを削除するための構文は、次のとおりです-

alter table yourTableName drop index `yourIndexName`;

まずテーブルを作成しましょう-

Mysql> create table DemoTable1469
   -> (
   -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> StudentName varchar(40),
   -> StudentAge int
   -> );
Query OK, 0 rows affected (0.78 sec)
>

以下は、列名にインデックスを追加するためのクエリです-

mysql> create index `Student Name_Index` on DemoTable1469(StudentName);
Query OK, 0 rows affected (0.33 sec)
Records: 0  Duplicates: 0  Warnings: 0

テーブルの説明を確認しましょう-

mysql> desc DemoTable1469;

これにより、次の出力が生成されます-

+-------------+-------------+------+-----+---------+----------------+
| Field       |        Type | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| StudentId   |     int(11) | NO   | PRI | NULL | auto_increment    |
| StudentName | varchar(40) | YES  | MUL | NULL |                   |
| StudentAge  |     int(11) | YES  |     | NULL |                   |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

以下は、インデックスを削除するためのクエリです-

mysql> alter table DemoTable1469 drop index `Student Name_Index`;
Query OK, 0 rows affected (0.23 sec)
Records: 0  Duplicates: 0  Warnings: 0

テーブルの説明をもう一度確認しましょう-

mysql> desc DemoTable1469;

これにより、次の出力が生成されます-

+-------------+-------------+------+-----+---------+----------------+
| Field       |        Type | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| StudentId   |     int(11) | NO   | PRI |    NULL | auto_increment |
| StudentName | varchar(40) | YES  |     | NULL    |                |
| StudentAge  |     int(11) | YES  |     |    NULL |                |
+-------------+-------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)

  1. テーブルのNULL値のみを置き換えるMySQLクエリ?

    このために、MySQLのnull値にプロパティISNULLを使用できます。まずテーブルを作成しましょう- mysql> create table DemoTable (    Name varchar(100) ); Query OK, 0 rows affected (0.53 sec) 挿入コマンド-を使用して、テーブルにいくつかのレコードを挿入します mysql> insert into DemoTable values('Robert'); Query OK, 1 row affected (0.23 sec) mysql> in

  2. MySQLでテーブル列をVARCHARからNULLに変更します

    変更するには、次の構文のようにCHANGEを指定してALTERコマンドを使用します- alter table yourTableName change yourColumnName yourColumnName datatype NULL DEFAULT NULL; まずテーブルを作成しましょう- mysql> create table DemoTable1356     -> (     -> FirstName varchar(30)     -> ); Query OK, 0 rows affected