当前位置:首页 > 芯闻号 > 充电吧
[导读]1、数据库:(1)创建数据库:CREATE DATABASE class;(2)删除数据库:DROP DATABASE class;(3)使用市局哭:USE class;2、数据库表(1)创建表:CR

1、数据库:

(1)创建数据库:

CREATE DATABASE class;

(2)删除数据库:

DROP DATABASE class;

(3)使用市局哭:

USE class;

2、数据库表

(1)创建表:

CREATE TABLE

[,<列名>

[,

例子:用于存储学生的基本信息,包含学号、姓名、性别、年龄、家庭住址;

创建表: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)查看表中的内容:select *from student_msg;


(4)删除表中的某一条内容:delete from student_msg where stu_id = 36;


(5)修改表中jungen的年龄为56:

update student_msg set stu_age = 56 where stu_id = 20;


(6)修改表列的的结构:

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)删除数据库表:drop table student_msg; 

(7)查询数据库中的内容;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;


本站声明: 本文章由作者或相关机构授权发布,目的在于传递更多信息,并不代表本站赞同其观点,本站亦不保证或承诺内容真实性等。需要转载请联系该专栏作者,如若文章内容侵犯您的权益,请及时联系本站删除( 邮箱:macysun@21ic.com )。
换一批
延伸阅读
关闭