

MySQL数据库基本操作(一)
source link: https://blog.51cto.com/u_15558033/5681773
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

MySQL数据库基本操作(一)
推荐 原创一、SQL语句 (mysql 数据库中的语言)








类比excel表格




类比excel表格


filed 字段名

二、DDL
1.DDL语句
用于创建数据库对象(库、表、索引等)
(1)创建新的数据库
create database 数据库名;
(2)创建新的表
create table 表名(字段1 数据类型,字段2 数据类型[, ...] [, primary key (主键名)]);
主键一般选择能代表唯一性的字段不允许取空值(NULL) ,一个表只能有一个主键。
create database 数据库名;
use 数据库名;
create table 表名 (id int not null, name char(10) not null, score decimal (5,2) ,passwd char (48) defalt' ',primary key (id)) ;
desc 表名;
not null 不允许为空值
default ' ' 默认值为空
primary key : 主键一般选择没有重复并且不为空值的字段
create table 表名 (id int(10) not null primary key, name varchar(40) ,age int(3));
create table food (id int(3) , name varchar (40) ,money decimal (3,1) ,primary key (id));


2.删除数据库和表
删除指定的数据表











三、DML
管理表中的数据记录
1.insert插入新数据
insert into 表名(字段1,字段2[,...]) values (字段1的值,字段2的值,...);
例子:
insert into 表名 (id,name,score,passwd) values (1,'自定义',70.5,passwd('123456')) ;
passwd('123456') :查询数据记录时,密码字串以加密形式显示:若不使用passwd(), 查询时以明文显示。
密码复杂性验证
insert into 表名 values(2,'自定义',90.5, 654321) ;
select * from 表名 ; 查询表的数据记录
insert插入表数据
在此之前需要进行查看desc table_name; 来查看表结构(有哪些字段,有无主键,主键是哪个字段,type,是否允许为空,是否有默认值)
使用insert into table_name进行插入,是根据查看到的表结构来判断,可以怎么写



Recommend
-
87
RAID阵列概述•廉价冗余磁盘阵列–RedundantArraysofInexpensiveDisks–通过硬件/软件技术,将多个较小/低速的磁盘整合成一个大磁盘–阵列的价值:提升I/O效率、硬件级别的数据冗余–不同RAID级别的功能、特性各不相同•RAID0,条带模式–同一个文档分散存放在不同磁盘–并行...
-
70
该文章不存在或者被删除 ...
-
81
数据库联系
-
48
Linux的基础
-
76
在Centos系统中,程序包管理器的核心是rpm: 其后端所使用rpm命令行工具; 前段使用yum命令行工具或dnf命令行工具;程序包管理的前...
-
6
MySQL之终端(Terminal)管理数据库、数据表、数据的基本操作 MySQL有很多...
-
5
MySQL数据库基本操作-DDL 目录
-
5
树莓派使用数据库时,优先选择sqlite数据库,但是sqlite是文件数据库同时仅针对于单用户的情况,考虑到多用户的情况,在树莓派上部署安装mariadb数据库服务(mysql的开源分支),通过读写锁事务等使用,可以实现多进程可以操作同一个数据库的同一个表的读写并行操...
-
5
mysql中对于数据库的基本操作 原创 公号运维家 2022-07-15 08:57:12
-
5
3.1 提出问题,引入“表“的概念与思维模式 table 表的概念: 数据库类似于厂库,而表呢就是对数据进行抽象分类的货架 注意:在创建数据库的时候一定要记得设置字符编码
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK