Mysql (3) operations on data tables _ MySQL

Source: Internet
Author: User
Mysql (3) operations on data tables bitsCN.com
Mysql (3) Operations on mysql-related data TABLES related to data TABLES 1. command for displaying data TABLES: show tables; command for displaying table information. If you do not have the permission to use a table, the table is not displayed. Command: DESCRIBE tbname; this command displays the structure of a table named tbname. 2. create table tbname (column name [1] data type, column name [2] data type, column name [3] data type ); this command is used to create a data table whose tbname is the table name. For example, create table guestbook (visitor VARCHAR (40), comments TEXT, entrydate DATETIME); 3. an important concept of using SELECT results to create a table relational database is that any data is composed of rows and columns, and the results of each SELECT statement are also tables composed of rows and columns. Command: create table test SELECT * FROM test2; this command is used to copy a TABLE by selecting all the content of a TABLE (without the WHERE clause. Command: create table test SELECT * FROM test2 WHERE 0; this command uses a WHERE clause that always fails to CREATE an empty TABLE. 4. modify the structure of a TABLE. alter table is useful. Command: alter table tbname add col_name type. the function of this command is to add a col_name column with the data type as the type for the TABLE tbname. Example: add a column name to the guestbook TABLE; alter table guestbook add name varchar (40); command: alter table tbname drop col_name; this command is used to delete a column named col_name from the tbname TABLE. for example, to delete a column named alter table guestbook drop name from the guestbook TABLE. Command: alter table tbname modify col_name type; this command is used to modify the data type of columns in the table. Example: change the name data type in the guestbook table. Alter table guestbook modify name TEXT; command: alter table tbname CHANGE oldcol_name newcol_name; this command is used to modify the column name. Example: alter table guestbook CHANGE name username; command: alter table oldtbname RENAME newtbname; this command is used to RENAME a TABLE. Example: change the name of the guestbook table. Alter table guestbook RENAME newguestbook; 5. run the drop table tb1name [, tb2name,...] command to delete one or more tables. Example: Delete a guestbook table. Drop table guestbook; 6. INSERT command to Data Table: INSERT [INTO] tbname [(col_name,...)] VALUES (express ,....) this command inserts data into a table. For example, insert data into the guestbook table. Insert into guestbook (visitor, comments, entrydate) VALUES ('sunnyboysac ', 'sunnyboysac', '2017-01-01 '); 7. example of inserting rows selected FROM other tables: insert into tbname (col1, col2) SELECT col3, col4 FROM tb1name; INSERT data queried FROM tb1name INTO columns col1 and col2. Same: REPLACEbitsCN.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.