MySql common operations SQL statement Summary

MySQL common operation here do some summary, which has been integrated into the code, tested and correct.
Copy the code code is as follows:

/ Create a database /
Create Database xuning_test;
/ indicating that the use of a database object /
use xuning_test;
/ add tables to the database and the structure definition table /
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,
the 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 lickly IS'),
(. 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 is, 'Beijing', 'This IS A frindsheep Boy' ),
(. 1, 'NAME_7', 'Men', 33 is, 'Beijing', 'This IS A frindsheep Boy'),
(. 1, 'NAME_8', 'man', 22 is, 'Beijing', ''),
( . 1, 'NAME_9', 'Men',. 11, 'Beijing', 'iS a frindsheep This Boy')
;
/ no query is successfully inserted /
SELECT from Person;
/
following are ways to search /
/
the name attribute column value /
SELECT name from Person;
/
adding conditions - according to sex /
SELECT name from Person WHERE sex = 'Men';
/
Can also be used as a condition for comparison operator - constant comma /
SELECT name, address from Person WHERE Age> 50;
/
Seen as objects to relational databases and tables --- = double table related - must be clear object-relational /
the 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
;
/
alias table query * /
use xuning_test;
SELECT c.NAME, Sex from Person WHERE c.age AS C> 40 and C .address = 'beijing';

Guess you like

Origin blog.51cto.com/11395518/2483431