įOREIGN KEY ( columnNmae) REFERENCES tableName ( columnNmae) SHOW CREATE DATABASE databaseName - Show the CREATE DATABASE statement - Table-LevelĬolumnName columnType columnAttribute. ![]() ![]() SELECT DATABASE() - Show the default database USE databaseName - Set the default (current) database SHOW DATABASES - Show all the databases in this server Database-LevelĭROP DATABASE databaseName - Delete the database (irrecoverable!)ĭROP DATABASE IF EXISTS databaseName - Delete if it existsĬREATE DATABASE databaseName - Create a new databaseĬREATE DATABASE IF NOT EXISTS databaseName - Create only if it does not exists Summary of MySQL Commands Used in this Tutorialįor detailed syntax, check MySQL manual "SQL Statement Syntax". In this tutorial, you have learned how to show the columns of a table by using MySQL SHOW COLUMNS command and DESC statement.Read " How to Install MySQL and Get Started" on how to install, customize, and get started with MySQL. | checkNumber | varchar(50) | NO | PRI | NULL | |Ģ rows in set ( 0.01 sec) Code language: SQL (Structured Query Language) ( sql ) | customerNumber | int(11) | NO | PRI | NULL | | SHOW COLUMNS FROM table_name WHERE expression įor example, to show only columns that start with the letter c, you use the LIKE operator as follows: mysql> SHOW COLUMNS FROM payments LIKE 'c%' The SHOW COLUMNS command allows you to filter the columns of the table by using the LIKE operator or WHERE clause: SHOW COLUMNS FROM table_name LIKE pattern row ***************************Īs you can see, the SHOW FULL COLUMNS command adds the collation, privileges, and comment columns to the result set. Privileges: select, insert, update, references Comment: mysql> SHOW FULL COLUMNS FROM payments \G To get more information about the column, you add the FULL keyword to the SHOW COLUMNS command as follows: SHOW FULL COLUMNS FROM table_name Code language: SQL (Structured Query Language) ( sql )įor example, the following statement lists all columns of the payments table in the classicmodels database. Or SHOW COLUMNS FROM table_name IN database_name Code language: SQL (Structured Query Language) ( sql )įor example, to get the columns of the orders table, you use the SHOW COLUMNS statement as follows: SHOW COLUMNS FROM orders Īs you can see the result of this SHOW COLUMNS command is the same as the result of the DESC statement. To show columns of a table in a database that is not the current database, you use the following form: SHOW COLUMNS FROM database_name.table_name Code language: SQL (Structured Query Language) ( sql ) To show the columns of a table, you specify the table name in the FROM clause of the SHOW COLUMNS statement. The more flexible way to get a list of columns in a table is to use the MySQL SHOW COLUMNS command. For example, the following statement is equivalent to the DESCRIBE above: DESC orders Ĭode language: SQL (Structured Query Language) ( sql ) MySQL SHOW COLUMNS command In practice, you use the DESC statement which is a shorthand of the DESCRIBE statement. | customerNumber | int(11) | NO | MUL | NULL | | ![]() | orderNumber | int(11) | NO | PRI | NULL | | ![]() | Field | Type | Null | Key | Default | Extra | Issue the USE command to switch to the database to classicmodels: mysql> USE classicmodels >mysql -u root -pĬode language: SQL (Structured Query Language) ( sql ) The following example demonstrates how to display columns of the orders table in the classicmodels database. To show all columns of a table, you use the following steps:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |