小白学习MySQL Day1 20240814

今天开始敲代码啦~

• Creating Tables
        • Syntax
• Tuple Manipulation
        • INSERT INTO, UPDATE, DELETE

一、Creating Tables

(1)Creating a schema

A schema consists of tables (relations), views, domains, assertions, collations, translations, and character sets.

语法:
CREATE SCHEMA 名字;
CREATE DATABASE 名字;
二选一,同样效果
 

(2)Creating a table

Remember to click on the schema first, then click the SQL tab.

A table cannot be created outside of a schema.

 表名之后,先写(    );再往括号里填充列名/属性。

 建表之前,想一想:

1)表有哪些属性?

2)每个属性 有什么限制条件:

数据类型? VARCHAR 和 CHAR ,字符需声明长度

是否非空?非空 NOT NULL

(3)实际操作

建议:总是为表指定一个主键,唯一标识每一个元组。

如果某一列是自增的,那么可以将其设置为 PRIMARY KEY

二、Tuple Manipulation

(1)INSERT INTO 语句
用于向表格中插入新的行/元组。

1) 插入新的行:
INSERT INTO 表名称 VALUES (值1, 值2,....);

When adding a value to every column, don’t have to list them:

2) 在指定的列中插入数据:

INSERT INTO 表名称 (列1, 列2,...) VALUES (值1, 值2,....);

此时需注意,非空的列必须赋值,否则可能报错。

插入多行: 

The order of column names must be consistent with the order of values.

(2)UPDATE 语句
用于修改表中的数据
UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值


• Changes values in specified rows based on WHERE conditions
• All rows where the condition is true have the columns set to the given values.
If no condition is given all rows are changed.
• Values are constants or can be computed from columns.

(3)DELETE 语句
用于删除表中的。Removes all rows, or those which satisfy a condition.
DELETE FROM 表名称 WHERE 列名称 = 值;


• If no condition is given then ALL rows are deleted.

  • 6
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值