数据定义语言和数据操纵语言简要概括(DDL,DML)

本篇对应语法内容参考主页前几篇

数据定义语言:用来描述数据库的框架

数据操纵语言DML:用来操纵表中数据的内容(增(insert into value) ,删(delete from),改(update set))

-- 删除数据库
drop database db;
-- 创建一个数据库
create database  if not exists db;
-- 进入数据库
use db;
-- 查看当前所有的数据库信息
show databases;
-- 创建表格
create table student(
s_id int,
s_name char(20),
s_age int,
s_book char(20)
);
select*from student;
-- 修改表的名字
rename table student to studentt;
rename table studentt to student;
-- 查看表结构
desc student;
-- 增加表中列;
alter table  student add column s_book char(20);
-- 删除表中列
alter table student drop column s_book;
desc student;
-- 修改表中列的类型
alter table student modify column s_class int;
-- 修改表中列的名称
alter table student change column s_class s_classt int;
alter table student change column s_classt s_class int;
-- 插入表中数据(插入多条数据用values,不写属性就是默认给全部的表插入数据)
alter table student modify column s_id char(20);
insert into student(s_id,s_name)value("421421401012","shazhongjin");
insert into student(s_id,s_name)values("1","zhang"),("2","wang"),("3","liu");
insert into student(s_age,s_class)values("12","1"),("13","2"),("14","3"),("15","4");
select*from student;
-- 数据更新(update set)
update student set s_age ="1" where s_id="421421401012" and s_name = "shazhongjin";
-- 数据删除 (delete from)
delete from student where s_id="2"; -- 条件删除是将带有条件的那条数据整行(记录,元祖)删除。
-- 与(记录,元祖)相对应的是(字段和属性)一个是行一个列
select *from student;

猜你喜欢

转载自blog.csdn.net/m0_65334415/article/details/130249531