学习内容
SQL第16课:创建表
Exercise 16 — Tasks
- Create a new table named
Database
with the following columns:
–Name
A string (text) describing the name of the database
–Version
A number (floating point) of the latest version of this database
–Download_count
An integer count of the number of times this database was downloaded
This table has no constraints.
相关的SQL内容
movies table schema
CREATE TABLE movies ( id INTEGER PRIMARY KEY, title TEXT, director TEXT, yearINTEGER, length_minutes INTEGER );
建具有可选表约束和默认值的表语句
CREATE TABLE IF NOT EXISTS mytable
( column Data Type Table Constraint DEFAULT default_value, another_column Data Type Table Constraint DEFAULT default_value, … );
常见的数据类型
表约束
输出结果
1.CREATE TABLE Database (
Name TEXT,
Version FLOAT,
Download_count INTEGER
);
结果和输入语句之间的对应关系,讲真,这部分内容自己掌握的不是很扎实,还需要继续推敲。继续从其他的SQL自学网站加深印象。待更新自己的学习笔记。
更改表
表:Movies
Exercise 17 — Tasks
- Add a column named Aspect_ratio with a FLOATdata type to store the aspect-ratio each movie was released in.
- Add another column named Language with a TEXT data type to store the language that the movie was released in. Ensure that the default for this language is English.
更改表以添加新列
ALTER TABLE mytable ADD column
Data TypeOptionalTableConstraintDEFAULT default_value;
改变表名
ALTERTABLE mytable RENAMETO new_table_name;
输出结果
1.
2.
删除表
SQL第18课:删除表
表1:Movies
表2:Boxoffice
Exercise 18 — Tasks
- We've sadly reached the end of our lessons, lets clean up by removing the Movies table
- And drop the BoxOffice table as well
删除表语句
DROPTABLEIFEXISTS mytable;
输出结果
1.
2.