Skip to Content
《Head First SQL》 (Chinese Edition), 2nd Edition
book

《Head First SQL》 (Chinese Edition), 2nd Edition

by Kimberly Fessel
June 2026
740 pages
13h 7m
Chinese
O'Reilly Media, Inc.
Content preview from 《Head First SQL》 (Chinese Edition), 2nd Edition

第 2 章 插入 数据:向表中添加数据

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

Image

是时候给墙壁“穿上新衣”了吗?创建数据库和表固然很有趣,但如果没有实际数据填充,这些精心设计的 SQL 结构又有何意义呢?

这就是本章要讲的内容。在这里,你将学习如何 使用 INSERT 命令向表中添加值 。你将看到一些INSERT语句的变体,并遇到那个你曾在各种“鬼故事”中听闻过的臭名昭著的NULL字符。不过别担心,你还将 通过对 CREATE TABLE 语句进行一些微调

要做的事情很多,所以不要拖延学习进度。让我们确保数据的安全存储。

使用表设置数据库

第 1 章中,你已经了解到可以将数据存储在 关系型数据库 中,该数据库包含 。你可以将信息视为各类类别,这些类别便成为 。而表中的行则存储单个条目的信息。

Image

添加任何数据之前,请先在 SQL 中规划并设置好数据结构。

再次与艾比联系

艾比需要一种方法来整理她的旅行笔记,你在上一章中已帮助她创建了一个名为travel_dbSQL 数据库以及一个名为locations表。现在,她准备开始添加信息了。

Image

Transact-SQL 用户,本章正是为你们准备的,因为你们很可能需要向表中插入数据。如果你主要从事数据分析工作,可能不会直接输入数据,但了解整个流程仍然很有帮助。

向表中插入数据

既然一切都已准备就绪,现在是时候将一行数据实际插入表中了。为此,你将使用一个名为INSERT 的新 SQL 命令。目标如下:

Image

请查看下面的模板语句,了解INSERT语句各部分的工作原理。请注意,第二组圆括号中的值必须与 与前一组括号中的列名 完全一致。

Image
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer
How to Overcome a Power Deficit

How to Overcome a Power Deficit

Cyril Bouquet, Jean-Louis Barsoux
Relational Power Is the New Currency of Hybrid Work

Relational Power Is the New Currency of Hybrid Work

Lebene Soga, Yemisi Bolade-Ogunfodun, Nazrul Islam, Joseph Amankwah-Amoah

Publisher Resources

ISBN: 0642572408114