MySQL基本语法学习
2017-09-30 13:48
387 查看
登录MySQL服务器 mysql -u root -p 创建数据库 create database samp_db character set gbk; 查询所有数据库 show databases; 创建表 use samp_db; create table students( id int unsigned not null auto_increment primary key, name char(8) not null, sex char(4) not null, age tinyint unsigned not null, tel char(15) null default "-" ); 向表中插入数据 insert into students values(NULL,"王刚" ,"男", 20,"13811371377"); insert into students values(NULL,"孙丽华" ,"女", 22,"18256973756"); insert into students values(NULL,"王永恒" ,"男", 23,"18812345678"); insert into students values(NULL,"李白" ,"男", 33,"17089898989"); 查询表中的数据 select * from students; select name from students; 条件查询 select * from students where sex="男";(查询students表中男同学) select * from students where age=20;(查询students表中年龄为20的学生) 更新表中的数据 update 表名称 set 列名称=新值 where 更新条件; update students set age=21 where name="王刚";(将王刚的年龄改成21) update students set tel=default where id=2;(将id为2的同学的手机号变成默认值"-") update students set name="张永恒",tel="1821324679" where name="王永恒";(将王永恒的名字改成张永恒,手机号改成18213245679) 删除表中的数据 delete from 表名称 where 删除条件 delete from students where id=4;(删除id=4的这个学生的数据) delete from students;(删除表中所有数据) 添加列 alter table 表名 add 列名 列数据类型 [after 插入位置]; alter table students add address char(60);(往students表中插入address列) alter table students add birthday date after age;(向students表的age列之后插入birthday列) 修改列 alter table 表名 change 列名称 列新名称 新数据类型; alter table students change tel telphone char(15) default "-";(将tel列名修改为telphone) 删除列 alter table 表名 drop 列名称; alter table students drop birthday;(删除students表中的birthday列) 重命名表 alter table 表名 rename 新表名; alter table students rename workmates;(将students表名修改为workmates) 删除整张表 drop table 表名; drop table workmates;(删除workmates表) 删除数据库 drop database 数据库名 drop database samp_db;(删除samp_db数据库)
相关文章推荐
- MYSQL学习笔记——基本语法
- MySQL学习笔记——基本语法
- MySql基本的语法(学习笔记)
- Mysql学习历程基本语法(2)--库操作
- Mysql学习历程基本语法(7)--时间日期类型
- mysql 基本语法学习1(数据库、数据表、数据列的操作)
- Mysql学习历程基本语法(4)--数据操作
- 与MSSQL对比学习MYSQL的心得(一)--基本语法
- mySql 基本语法学习笔记
- MySql基本语法(学习笔记)
- Mysql学习笔记一——curd基本语法
- MySql基本语法(学习笔记)
- Mysql学习历程基本语法(8)-字符串类型
- Mysql学习历程基本语法(9)-列属性
- 与MSSQL对比学习MYSQL的心得(一)--基本语法
- Mysql学习历程基本语法(3)--表操作
- Mysql学习历程基本语法(6)--数据类型
- Mysql学习历程基本语法(1)
- MYSQL的学习笔记------MYSQL的基本语法
- XPath学习:基本语法(三)