当前位置:Gxlcms > 数据库问题 > sql常用命令之增删改查

sql常用命令之增删改查

时间:2021-07-01 10:21:17 帮助过:26人阅读

current_database();

3. 创建数据库

create database db_name;

4. 选择某个数据库

use db_name;

5. 显示当前数据库下的表

show tables;

6. 创建表 create table

create table if not exists my_test(
   id INT UNSIGNED AUTO_INCREMENT,
   name_people VARCHAR(40) NOT NULL,
     submission_time DATETIME,
   PRIMARY KEY(id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;

7. 描述表结构DESC或者DESCRIBE、show columns from

DESC my_test;
SHOW COLUMNS FROM my_test; #显示表结构

技术图片

8. 插入数据 insert into

INSERT my_test(
    id,
    name_people,
    submission_time
)
VALUES
    (1, Mary, NOW());

9 .查询 select

select * from my_test;
select name_people from my_test;
select name_peole from my_test where id=1;

技术图片

 

 

10. 删除一条记录 delete

delete from my_test where id=1;

11. 删除表中的所有记录,但是保存原来的表结构

delete from my_test;

12. 更新表的某一列 update

UPDATE my_test SET name_people = 陛下 WHERE id=1

13. 更新多列数据,用 ‘,‘ 逗号隔开

UPDATE my_test SET name_people = 将军, submission_time = NOW() WHERE id=1

 

#欢迎交流

sql常用命令之增删改查

标签:charset   values   char   int   常用   now()   weight   select   test   

人气教程排行