今天开始敲代码啦~
• 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.

3055

被折叠的 条评论
为什么被折叠?



