Zmiana nazwy tabeli poleceniem RENAME TABLE

Autor podstrony: Krzysztof Zajączkowski

Stronę tą wyświetlono już: 11564 razy

Pomyłka w nazwie tabeli? Nie martw się mój stary Jedi przyjacielu, jest polecenie w SQL-u, które wybawi cię z kłopotów RENAME TABLE zwą go tak przewrotnie. Jak jego użyć? To bardzo proste, pozwól, pokażę ci tutaj proszę:

RENAME TABLE library.books TO library.old_books;

W konsoli wyglądać powinno to mniej więcej tak:

mysql -u root -p
Enter password: **************
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 172
Server version: 5.6.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

mysql> RENAME TABLE library.books TO library.old_books;
Query OK, 0 row affected (0.00 sec)
mysql> SHOW TABLES IN library;
+-------------------+
| Tables_in_library |
+-------------------+
| old_books         |
+-------------------+
1 row in set (0.00 sec)
mysql> RENAME TABLE library.old_books TO library.books;
Propozycje książek