Home > Database > Mysql Tutorial > body text

数据操纵语言中数据的操作

WBOY
Release: 2016-06-07 16:20:08
Original
1175 people have browsed it

--表数据的操作 --输入数据 select * from 学生 --说明 :用在insert与表名之间的into是一个可选关键字 insert into 学生 (学号,姓名,性别,年龄,专业) values ('003','杨丽','女',18,'计科') insert into 学生 (学号,姓名,性别,年龄,专业) values ('004','杨

   --表数据的操作

  --输入数据

  select * from 学生

  --说明 :用在insert与表名之间的into是一个可选关键字

  insert into 学生 (学号,姓名,性别,年龄,专业)

  values ('003','杨丽','女',18,'计科')

  insert into 学生 (学号,姓名,性别,年龄,专业)

  values ('004','杨丽','女',18,'计科')

  delete 学生 where 学号 = '004'

  alter table 学生

  add constraint ck check( 性别 in ( '男' ,'女'))

  insert into 学生

  (学号,姓名,性别,年龄,专业)

  values ('005','张三','男',18,'网络工程')

  --修改表中的数据

  --数据操纵语言中修改数据即是更新数据用update关键字

  /*

  语法表示为:

  update 表名

  set 列名 = 新数据

  where 条件表达式

  */

  use test

  go

  alter table 学生

  add 备注 char(20)

  update 学生

  set 性别 = '已毕业'

  --根据条件跟新数据

  update 学生

  set 备注 = '在读生'

  where 姓名 = '王芳'

  --删除数据

  --每次删除一行记录

  /*

  语法结构

  deleted 表名

  where 条件表达式

  */

  delete 学生

  where 学号 = '005'

  --一次性删除表的所有记录 :清空表格

  --有两种方法

  --其中方法二更快

  --方法一;

  delete 选课

  --方法二:

  truncate table 选课

  //

  --删除表

  drop table hh

  //

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!