/*創建一個數據庫*/ create database xuning_test; /*說明當時使用數據庫對象*/ use xuning_test; /*向數據庫中添加表并且定義表的結構*/ 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 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') ; /*查詢時否成功插入*/ select * from person; /*下面是多種查詢方式*/ /*根據列的名稱屬性值*/ select name from person; /*添加條件-根據性別*/ select name from person where sex = 'men'; /*也可以用比較符作為條件--一定逗號隔開*/ select name,address from person where age > 50; /*看做對象去使用數據庫和表的關系=---雙表關聯--對象關系一定要明確*/ 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 ; /*使用表的別名進行查詢*/ use xuning_test; select c.name,sex from person as c where c.age > 40 and c.address='beijing';