Basic operations on MySQL Data Tables and basic operations on mysql DATA

Source: Internet
Author: User

Basic operations on MySQL Data Tables and basic operations on mysql DATA


The following outlines are provided in advance, and details and examples are provided tomorrow:


1. Create a data table

1) Create Table syntax

2) use primary key constraints

3) use foreign key constraints

4) use non-empty Constraints

5) Use uniqueness constraints

6) use default Constraints

7) set the attribute value of the table to automatically increase


2. view the data table structure

1) view the basic table structure statement DESCRIBE

2) view the detailed TABLE structure statement SHOW CREATE TABLE


3. modify a data table

1) modify the table name

2) modify the field data type

3) modify the field name

4) add fields

5) delete a field

6) modify the field arrangement position

7) change the storage engine of the table

8) Delete the foreign key constraint of the table


4. delete a data table

1) Delete the table not associated

2) Delete the primary table associated with another table


V. Basic Database Operations-Comprehensive Cases


Change MYSQL Data Table Name

It is impossible to implement a query statement.
One statement is
Rename table tb_name TO new_name;
I teach you a trick.
Use the program to output a set of statements and execute them in mysql.

Example: php
I would like to write the program code to you, do not know your mysql DATA STRUCTURE, 154651166 park412@hotmail.com
You add me
If you are interested, you can solve it for you.

Basic SQL database operations

Command Line
1. display the Database List on the current database server: mysql> show databases;
2. CREATE a DATABASE: mysql> create database name;
3. CREATE a data TABLE: mysql> USE Database Name; mysql> create table Name (field name VARCHAR (20); field name CHAR (1 ));
4. delete a DATABASE: mysql> drop database name;
5. delete a data TABLE: mysql> drop table name;
6. Clear the table records: mysql> delete from table name;
7. INSERT records INTO the table: mysql> insert into table name VALUES ("hyq", "M ");
8. UPDATE table data: mysql-> UPDATE table name SET field name 1 = 'A', field name 2 = 'B' WHERE field name 3 = 'C ';
9. load data into a data table in text mode: mysql> load data local infile "d:/mysql.txt" into table name;
10. Import the. SQL FILE command: mysql> USE Database Name; mysql> source d:/mysql. SQL;
11. Run the command line to change the root password: mysql> update mysql. user set password = password ('new password') where user = 'root'; mysql> flush privileges;
12. three methods to change the password: mysql> update user set password = password ('000000') where user = 'joy _ pen'; mysql> flush privileges; mysql> set password for 'joy _ oen' = password ('000000'); mysql> grant usage on *. * to 'joy _ pen' identified by '20140901 ';
1. Create a database
Command: create database <database Name> For example: create a database named xhkdb mysql> create database xhkdb;
2. display all databases
Command: show databases (Note: There is finally s) mysql> show databases;
3. delete a database
Command: drop database <database Name> example: delete a database named xhkdb mysql> drop database xhkdb;
4. Connect to the database
Command: use <Database Name> For example: if the xhkdb Database exists, try to access it: mysql> use xhkdb; on-screen prompt: Database changed
5. mysql> select database () currently selected (connected ();
6. Table information contained in the current database: mysql> show tables; (Note: There is a last s)
Iii. Table operations. A database should be connected before operations
1. Create a table
Command: create table <table Name ...... remaining full text>

Related Article

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.