mysql-表结构(表名、列)增删改查

一、 表结构(表名、列)

列描述:列名、数据类型、是否为空

1. 创建表

mysql> create table student

    -> (sno char(4) not null,

    -> sname char(10),

       -> ssex char(2));

**查看当前数据库下有哪些表  show tables;

**查看表结构:desc student;

2. 修改表 alter table 表名

(1) 修改表的名字

mysql> alter table student

     -> rename to s;

(2) 添加列

添加1个列

mysql> alter table s

-> add sage int;

同时添加多个列

mysql> alter table s

     -> add (a char(3),b int);

(3) 修改列

mysql> alter table s

    -> modify sname char(20) not null;

(4) 删除列

mysql> alter table s

    -> drop column b;

3. 删除表

mysql> drop table s;

二、 表数据(增、删、改、查)

1. 插入数据

Insert into 表名

Values(值1,值2)

**注意事项:

(1) 提供的值或者与表的字段一一对应,或者与列清单一一对应。

(2) 字符型和日期型数据要加’’

(3) not null的字段必须添加数据

mysql> insert into student

    -> values('0001','李莉','女',18,'CS');

mysql> insert into student(sno,sname)

    -> values('0002','李丽');

2. 更新数据

语法:

update 表名

set 数据名 = 新数据

where 寻找的数据名 = 数据;

3. 删除数据

Delete from 表名

Where sno = ‘0003’

mysql> delete from student

    -> where sno = '0003';

猜你喜欢

转载自blog.csdn.net/m0_59069134/article/details/126830735
今日推荐