Learn SQL: Manipulation

Learn how to use SQL to access, create, and update data stored in a database

Start[missing "en.views.course_landing_page.learn-sql.course_illustration" translation]

Key Concepts

Review core concepts you need to learn to master this subject

SQL CREATE TABLE statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, .... );

The SQL CREATE TABLE statement is used to create new tables in a database. Column names and types are provided as a comma-separated list of values between ().

The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold (e.g. TEXT, INTEGER, etc.).

SQL CREATE TABLE statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, .... );

The CREATE TABLE SQL statement is used to create a table in a database. A list of column names and their data types must be passed in at time of creating the table. This set of columns is defined as a comma-separated list inside ().

Data types for each column should be chosen to suit the data they store. For instance, the INTEGER type can be defined as one of below is used for number values, and TEXT is used to store string values.

SQL Insert Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, .... );

The INSERT INTO statement is used to insert new records in a table.

The INSERT INTO statement has two forms as shown in the code block, You can define the coloumns to insert values or insert directly based on the column order.

SQL Update Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, .... );

The SQL UPDATE statement is used to update records in a table.

The UPDATEstatement usually includes a WHERE clause for specifying which record or records that should be updated.

SQL Alter Statement

CREATE TABLE table_name ( column1 datatype, column2 datatype, .... );

The SQL ALTER TABLE statement is used to modify an existing table. When combined with the ADD clause, it is used to add a new column definition to a table.

SQL Table - Column Constraints

CREATE TABLE table_name ( column1 datatype, column2 datatype, .... );

SQL Column Constraints are the rules that you can apply on values of individual columns.

Some of the available constraints in SQL are:

NOT NULL: This constraint requires that a value must be supplied for this column, it cannot be NULL.

UNIQUE: This constraint requires that all the values in the column must be unique.

PRIMARY KEY: A primary key is a field which can uniquely identify each row in a table.

DEFAULT: This constraint specifies a default value for the column when no value is specified by the user.

Manipulation
Lesson 1 of 1
  1. 1

    SQL, Structured Query Language, is a programming language designed to manage data stored in relational databases. SQL operates through simple, declarative statements. This keeps data ac...

  2. 2

    Nice work! In one line of code, you returned information from a relational database. [...] We'll take a look at what this code means soon, for now, let's focus on what relational databases are...

  3. 3

    The code below is a SQL statement. A statement is text that the database recognizes as a valid command. Statements always end in a semicolon [...] . [...] Let's break down the components of...

  4. 4

    [...] statements allow us to create a new table in the database. You can use the [...] statement anytime you want to create a new table from scratch. The statement below creates a new table nam...

  5. 5

    The [...] statement inserts a new row into a table. You can use the [...] statement when you want to add new records. The statement below enters a record for Justin Bieber into the [...] tabl...

  6. 6

    [...] statements are used to fetch data from a database. In the statement below, [...] returns all data in the [...] column of the [...] table. [...] 1. [...] is a clause that indica...

  7. 7

    The [...] statement adds a new column to a table. You can use this command when you want to add columns to a table. The statement below adds a new column [...] to the [...] table. [...] 1...

  8. 8

    The [...] statement edits a row in a table. You can use the [...] statement when you want to change existing records. The statement below updates the record with an [...] value of [...] to ...

  9. 9

    The [...] statement deletes one or more rows from a table. You can use the statement when you want to delete existing records. The statement below deletes all records in the [...] table with no...

  10. 10

    Constraints that add information about how a column can be used are invoked after specifying the data type for a column. They can be used to tell the database to reject inserted data that does no...

  11. 11

    Congratulations! You've learned six commands commonly used to manage data stored in a relational database and how to set constraints on such data. What can we generalize so far? SQL is a program...

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo

Learn SQL: Manipulation

Start[missing "en.views.course_landing_page.learn-sql.course_illustration" translation]