sql语句没有默认值_Part 3 | SQL学习:创建/更改/删除

学习内容

SQL第16课:创建表

Exercise 16 — Tasks

  1. 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, … );
常见的数据类型

4cf2bcf4e2cf22b5fa806b169fb6cc98.png
表约束

9aa56af7cf1a2431f2dc4c97413edc9b.png

输出结果

1.CREATE TABLE Database (
Name TEXT,
Version FLOAT,
Download_count INTEGER
);

eb743a9bec9ef4a70b200336ed992019.png

结果和输入语句之间的对应关系,讲真,这部分内容自己掌握的不是很扎实,还需要继续推敲。继续从其他的SQL自学网站加深印象。待更新自己的学习笔记。


更改表

表:Movies

46c1499a186c0c93e99438f7e907bed5.png

Exercise 17 — Tasks

  1. Add a column named Aspect_ratio with a FLOATdata type to store the aspect-ratio each movie was released in.
  2. 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

bdd066153a85ab02a1b709fcd41f053f.png

表2:Boxoffice

0bd7c849f80526b7c7dec3408398c0e8.png

Exercise 18 — Tasks

  1. We've sadly reached the end of our lessons, lets clean up by removing the Movies table
  2. And drop the BoxOffice table as well

删除表语句

DROPTABLEIFEXISTS mytable;

输出结果

1.

2.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值