1、數(shù)據(jù)庫:
(1)創(chuàng)建數(shù)據(jù)庫:
CREATE DATABASE class;
(2)刪除數(shù)據(jù)庫:
DROP DATABASE class;
(3)使用市局哭:
USE class;
2、數(shù)據(jù)庫表
(1)創(chuàng)建表:
CREATE TABLE
(
[,<列名>
[,
例子:用于存儲學生的基本信息,包含學號、姓名、性別、年齡、家庭住址;
創(chuàng)建表:mysql> CREATE TABLE strudent_msg(stu_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,stu_name VARCHAR(30) NOT NULL,stu_sex VARCHAR(2) NOT NULL,stu_age INT NOT NULL,stu_adress VARCHAR(100),PRIMARY KEY (stu_id));
Query OK, 0 rows affected (0.09 sec);
(2)向表中插入3條記錄:
insert into student_msg values(20,'renyunjun','na',26,'beijing');
insert into student_msg values(36,'sanmao','na',25,'shenzheng');
insert into student_msg values(15,'chaochao','na',25,'biejing');
(3)查看表中的內(nèi)容:select *from student_msg;
(4)刪除表中的某一條內(nèi)容:delete from student_msg where stu_id = 36;
(5)修改表中jungen的年齡為56:
update student_msg set stu_age = 56 where stu_id = 20;
(6)修改表列的的結(jié)構(gòu):
ALTE TABLE
[ALTE COLUMN<列名>
ALTER TABLE student_msg ADD enter_scol DATE;
ALTER TABLE student_msg ADD enter_scol DATE;
ALTER TABLE student_msg ADD end_scol VARCHAR(20);
update student_msg set enter_scol = '2010.9.1' where stu_id=20;
update student_msg set end_scol = '2014.7.7' where stu_id=20;
update student_msg set enter_scol = '2010.9.1' where stu_id=15;
update student_msg set end_scol = '2014.7.7' where stu_id=15;
(6)刪除數(shù)據(jù)庫表:drop table student_msg;?
(7)查詢數(shù)據(jù)庫中的內(nèi)容;select stu_id ,stu_name from?student_msg ;
(8)查詢所有學生的學號和姓名并按年齡排序;select stu_id ,stu_name from?student_msg order ?by stu_age;
(9)通過where語句指定條件查詢:select *from student_msg where stu_age<40;