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 ';