Summary of SQL statements for common MySql operations and MySql SQL statements

Source: Internet
Author: User

Summary of SQL statements for common MySql operations and MySql SQL statements

Common MySQL operations are summarized here, which has been integrated into the code and proven to be correct.
Copy codeThe Code is as follows:
/* Create a database */
Create database xuning_test;
/* Description of the database objects used at the time */
Use xuning_test;
/* Add a table to the database and define the table structure */
Create table person (
Id int not null,
Name varchar (16) not null,
Sex varchar (16) not null,
Age int not null,
Address varchar (128) not null,
Remark varchar (512) not null
);
/* Insert data into the database table */
Insert into person value
(1, 'name _ 1', 'men', 99, 'beijing', 'This is a frindsheep boy '),
(2, 'name _ 2', 'men', 88, 'shanghai', 'OK great '),
(1, 'name _ 3', 'Man ', 77, 'guangzhou', 'this is lickly '),
(1, 'name _ 4', 'men', 66, 'beijing', 'This is a frindsheep boy '),
(1, 'name _ 5', 'men', 55, 'beijing', 'you dont going to shool '),
(1, 'name _ 6', 'Man ', 44, 'beijing', 'This is a frindsheep boy '),
(1, 'name _ 7', 'men', 33, 'beijing', 'This is a frindsheep boy '),
(1, 'name _ 8', 'man', 22, 'beijing ',''),
(1, 'name _ 9', 'men', 11, 'beijing', 'This is a frindsheep boy ')
;
/* Whether the query is successful */
Select * from person;
/* The following are multiple query methods */
/* Attribute Value Based on column name */
Select name from person;
/* Add conditions-based on Gender */
Select name from person where sex = 'men ';
/* You can also use a comparison character as a condition-separated by commas */
Select name, address from person where age> 50;
/* View the relationship between the database and the table as an object = --- double table Association -- the object relationship must be clear */
Select xuning_test.person.name, xuning_test.person.id, xuning_test.person.age, xuning_test.person.address
From xuning_test.person, test1.test _ xuning
Where xuning_test.person.id = test1.test _ xuning. id
;
/* Query using the table alias */
Use xuning_test;
Select c. name, sex from person as c where c. age> 40 and c. address = 'beijing ';

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.