欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

mysql 数据库 sql 语句摘要

最编程 2024-09-30 18:20:23
...

db:数据库名;tb:表名

查看所有数据库:show databases

创建数据库:create database db

删除数据库:drop database db

使用指定数据库:use db

查看正在使用的数据库:select database()

创建表:create table tb ( id int, name varchar(20) )

表存在时删除:drop table if exists tb

显示指定数据库中的所有表:show tables

查看创建表时用的 sql 语句:show create table tb

查看指定表中所有数据:select * from tb

——指定字段:select id, name from tb

——指定条件查询条件:select * from tb where age > 20

——对查询数据进行排序:order by age asc|desc 或是 limit 100 或是 like '%xxx%'

eg:select title from picture where title like "%JPG" order by id asc limit 20;

查看表字段:desc tb

修改表字段名:alter table tb change old_filed new_filed varchar(20)

删除表数据:delete from tb where age > 30

向表中插入数据:insert into tb values("field","field","field",field)

eg:insert into tb (student_id, name, age) values (101, 'Alice', 20), (102, 'Tony', 40);

改变表结构:alter table tb add pid int

——删除列:alter table tb drop column column_name

——修改列:alter table tb alter column column_name new_type

修改表名:rename table old_table_name to new_taable_name

更新表数据:update tb set column1 = value, ... where xxx

删除表数据:delete from tb where xxx

导出数据库数据到指定:mysqldump -u root -p db > C:/xxx.sql 然后输入密码

导入数据库数据:use databasename;

source C:/init.sql

推荐阅读