MySQL基礎四

來源:互聯網
上載者:User

標籤: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 beautySET phone = ‘13899999999‘WHERE    NAME LIKE ‘%唐%‘

 

4 刪除語句4.1 刪除語句的基本介紹
delete from 表名 [where 篩選條件];
4.2 刪除語句的應用
  • 樣本:刪除姓名包含唐的女神
DELETEFROM    beautyWHERE    NAME LIKE ‘%唐%‘;

 

MySQL基礎四

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.