码迷,mamicode.com
首页 > 数据库 > 详细

MySQL基础四

时间:2018-08-26 18:31:59      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:var   基础   val   姓名   应用   insert   value   create   mysql基础   

1 DML语言

1.1 DML语言的基本介绍

  • DML语言,数据操作语言。

1.2 DML语言的分类

  • 插入:insert
  • 更新:update
  • 删除:delete

 

2 插入语句

2.1 插入语句的语法

insert into 表名 (列名,列名,……) values (值1,值2,……);

2.2 准备(导入数据)

USE `girls`;

DROP TABLE IF EXISTS `admin`;

CREATE TABLE `admin` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(10) NOT NULL,
  `password` varchar(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

insert  into `admin`(`id`,`username`,`password`) values (1,john,8888),(2,lyt,6666);

DROP TABLE IF EXISTS `beauty`;

CREATE TABLE `beauty` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(50) NOT NULL,
  `sex` char(1) DEFAULT ,
  `borndate` datetime DEFAULT 1987-01-01 00:00:00,
  `phone` varchar(11) NOT NULL,
  `photo` blob,
  `boyfriend_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;

insert  into `beauty`(`id`,`name`,`sex`,`borndate`,`phone`,`photo`,`boyfriend_id`) values (1,柳岩,,1988-02-03 00:00:00,18209876577,NULL,8),(2,苍老师,,1987-12-30 00:00:00,18219876577,NULL,9),(3,Angelababy,,1989-02-03 00:00:00,18209876567,NULL,3),(4,热巴,,1993-02-03 00:00:00,18209876579,NULL,2),(5,周冬雨,,1992-02-03 00:00:00,18209179577,NULL,9),(6,周芷若,,1988-02-03 00:00:00,18209876577,NULL,1),(7,岳灵珊,,1987-12-30 00:00:00,18219876577,NULL,9),(8,小昭,,1989-02-03 00:00:00,18209876567,NULL,1),(9,双儿,,1993-02-03 00:00:00,18209876579,NULL,9),(10,王语嫣,,1992-02-03 00:00:00,18209179577,NULL,4),(11,夏雪,,1993-02-03 00:00:00,18209876579,NULL,9),(12,赵敏,,1992-02-03 00:00:00,18209179577,NULL,1);

DROP TABLE IF EXISTS `boys`;

CREATE TABLE `boys` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `boyName` varchar(20) DEFAULT NULL,
  `userCP` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

insert  into `boys`(`id`,`boyName`,`userCP`) values (1,张无忌,100),(2,鹿晗,800),(3,黄晓明,50),(4,段誉,300);

2.3 插入语句的应用

  • 示例:在女神表中新增一条数据
INSERT INTO beauty (
    id,
    NAME,
    sex,
    borndate,
    phone,
    photo,
    boyfriend_id
)
VALUES
    (
        13,
        唐艺昕,
        ,
        1990-04-23,
        18988888888,
        NULL,
        2
    );

 

3 修改语句

3.1 修改语句的语法

update 表名 set=值,……,[where 筛选条件]

3.2 修改语句的应用

  • 示例:修改beauty表中姓唐的女神的电话为13899999999
UPDATE beauty
SET phone = 13899999999
WHERE
    NAME LIKE %唐%

 

4 删除语句

4.1 删除语句的基本介绍

delete from 表名 [where 筛选条件];

4.2 删除语句的应用

  • 示例:删除姓名包含唐的女神
DELETE
FROM
    beauty
WHERE
    NAME LIKE %唐%;

 

MySQL基础四

标签:var   基础   val   姓名   应用   insert   value   create   mysql基础   

原文地址:https://www.cnblogs.com/xuweiweiwoaini/p/9537700.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!