4

MySQL数据库基本操作(一)

 2 years ago
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.
neoserver,ios ssh client

MySQL数据库基本操作(一)

推荐 原创

苦糖? 2022-09-16 09:52:22 ©著作权

文章标签 字段 表名 主键 文章分类 Java 编程语言 yyds干货盘点 阅读数296

一、SQL语句 (mysql 数据库中的语言)

MySQL数据库基本操作(一)_主键
MySQL数据库基本操作(一)_主键_02
MySQL数据库基本操作(一)_主键_03
MySQL数据库基本操作(一)_主键_04
MySQL数据库基本操作(一)_表名_05
MySQL数据库基本操作(一)_主键_06
MySQL数据库基本操作(一)_主键_07
MySQL数据库基本操作(一)_字段_08

类比excel表格

MySQL数据库基本操作(一)_主键_09
MySQL数据库基本操作(一)_表名_10
MySQL数据库基本操作(一)_表名_11
MySQL数据库基本操作(一)_主键_12

 类比excel表格

MySQL数据库基本操作(一)_字段_13
MySQL数据库基本操作(一)_主键_14

filed 字段名

MySQL数据库基本操作(一)_字段_15

二、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));

MySQL数据库基本操作(一)_表名_16

MySQL数据库基本操作(一)_表名_17

MySQL数据库基本操作(一)_主键_18

MySQL数据库基本操作(一)_表名_19
MySQL数据库基本操作(一)_主键_20

 2.删除数据库和表

删除指定的数据表

MySQL数据库基本操作(一)_主键_21
MySQL数据库基本操作(一)_主键_22
MySQL数据库基本操作(一)_字段_23
MySQL数据库基本操作(一)_表名_24
MySQL数据库基本操作(一)_字段_25
MySQL数据库基本操作(一)_字段_26
MySQL数据库基本操作(一)_主键_27
MySQL数据库基本操作(一)_主键_28
MySQL数据库基本操作(一)_字段_29
MySQL数据库基本操作(一)_字段_30
MySQL数据库基本操作(一)_字段_31

三、DML

管理表中的数据记录

insert: 插入新数据update: 更新原有数据delete: 删除不需要的数据

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进行插入,是根据查看到的表结构来判断,可以怎么写
MySQL数据库基本操作(一)_主键_32
MySQL数据库基本操作(一)_表名_33
MySQL数据库基本操作(一)_表名_34

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK