SQL Command Essentials: The Must-Know Statements, Explained

UPI Study › Courses › Database Programming › Free lessons › Lesson 1.6 Free with a free account

SQL Command Essentials: The Must-Know Statements

Database Programming · Chapter 1: Getting Started with Databases and SQL SetupSection 1.6 · lesson 6 of 768 min · free with a free account

← DDL, DML, and DCL in MySQL: What They Do and When to Use ThemNext lesson: Installing Your Database Environment — MySQL and SQL Server Express Setup Guide →

A free account plays all of Chapter 1 and 3 more lessons of Database Programming. Create a free account →

Earn 3 college credits for Database ProgrammingRecommended for credit by NCCRS · Computer Science 381 · self-paced · one payment, lifetime access

In this lesson

Read SQL statement parts and run the five core commands safely.

  • Identify keywords, identifiers, literals, clauses, and delimiters in a statement
  • Write comments and handle case sensitivity across MySQL and SQL Server
  • Use CREATE TABLE, INSERT, SELECT, UPDATE, and DELETE on a practice table
  • Read error messages and repair a statement one issue at a time

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (986 words). Read along, or search it.

Opening Question

DELETE Without a WHERE Clause

Leo sees delete from customers, with no where clause. Does that remove one customer, or every record? Reading a statement's parts is how you answer before pressing Run. We will use a disposable copy, with fictional course data. The examples run in SQLite. MySQL and SQL Server share these basic commands, while types, identifier rules, and diagnostics have important differences.

Statement Anatomy

Keywords, Identifiers, Literals, and Clauses

A statement is one complete instruction. Select, from, and where are keywords, with meanings defined by the language. Customers, first name, and city are identifiers: names chosen for database objects. Some keywords are reserved, so avoid them when choosing names. Pune in single quotes is a literal: a fixed value written into the statement. Numbers normally need no text quotes; date literals use quotes. A clause combines a keyword with its details. Commas separate columns, equals compares values, and a semicolon terminates the statement.

Delimiters

Commas, Parentheses, Quotes, and Semicolons

A delimiter marks a boundary. Commas separate list entries, parentheses group pieces, quotes surround text, and semicolons end statements. Whitespace can separate tokens and improve layout, but splitting a keyword or losing a required boundary changes the statement. Use semicolons consistently, including in SQL Server where some statements require them. Go and MySQL's delimiter command belong to client tools. Names containing spaces need dialect-specific quoting: backticks in MySQL, brackets in SQL Server. Descriptive names with underscores avoid that distraction.

Comments

Dash, Hash, and Block Comments

A comment is a note for human readers, which the engine ignores. Two dashes introduce an end-of-line comment. For portable MySQL usage, follow the dashes with a space. MySQL also accepts hash comments; SQL Server does not use that form. Slash-star opens a block comment, and star-slash closes it. The block can span lines, as this example does. Explain why a statement exists, or temporarily disable an entire statement. Commenting out only a filter can accidentally broaden a data-changing command.

Case Sensitivity

Keywords, Identifiers, and Collations

Case sensitivity means treating uppercase and lowercase as different. Select and SELECT represent the same keyword in these systems. Identifier case is a separate issue. MySQL table-name behavior depends on platform and configuration; SQL Server identifier behavior follows relevant collations. A collation controls text comparison and sorting, including case behavior. Do not assume Pune and lowercase pune compare the same everywhere. Write names exactly as created. Consistent uppercase keywords and lowercase descriptive names make scripts easier to inspect and move.

CREATE TABLE

Building an Empty Customers Table

Create table builds an empty structure. Our disposable customers table keeps only identifier, first name, and city from the course schema. The identifier is the primary key, distinguishing records. Integer stores whole-number identifiers; varchar fifty declares a text column in this example. SQLite accepts that type spelling, but does not enforce the fifty-character limit. MySQL and SQL Server have their own type and length rules. Run the creation file against our fresh practice database. It succeeds quietly; creating structure does not by itself add customer rows.

INSERT

Adding Asha and Ben

Insert into customers names the destination. The column list identifies which properties each incoming row supplies. Values must match those columns in number and order. We add Asha and Ben, keeping their canonical identifiers and cities. Run the file. Its select statement reads back the records, making the insertion observable without inventing an affected-row message. The result contains the new records. Its definition is the same; the insert changed its contents.

SELECT

Reading the Customer in Pune

Select reads chosen columns, from a source, keeping rows that pass where. Here the condition asks for Pune. The statement does not alter the prepared records. Run it, and the result shows Asha and Pune. Recognizing a read is useful, but always inspect the exact statement. A script can contain a select and a later change in the same file.

UPDATE

Moving Asha to Mumbai

Update names existing rows to change. Set supplies the new city, and where limits the target to customer ID one. Run it. Asha's city becomes Mumbai in this disposable copy; Ben's city remains Leeds. The selected identifier, rather than first name, makes the intended target unambiguous. Without where, this update would target every row.

DELETE

Removing Ben by Identifier

Delete removes rows. This where clause restricts the command to customer ID two, which identifies Ben. Run it. The readback shows only Asha, because the matching Ben row has been removed. The customers structure remains available. Removing rows is different from using drop table.

Error Messages

A Misspelled Table Name

An error message describes what the engine could not accept. This file misspells the customers identifier. Run it, and read the description first. The actual SQLite diagnostic names the missing table, custmers. SQLite's shell labels this a parse error, but the grammar is fine: the table is missing. A syntax error breaks the language's writing rules. Use the error number when your engine supplies one, but read the description and location before searching a catalog.

Fixing Errors

Correct One Issue, Then Rerun

Correct the identifier, and run again. The repaired file returns Asha, confirming that the intended source now resolves. For syntax errors, examine the reported spot and the token immediately before it. A missing comma may confuse the engine at the following value. Check keyword and object spelling, paired quotes and parentheses, and matching counts of columns and values. Fix one issue, then rerun.

Quick Check

Changes Inside a Rolled-Back Transaction

Quick check: begin a transaction, update without where, delete without where, then roll back. The final select reads the remaining records. What does it return in this SQLite practice database? Read the whole script, including its transaction boundary. Pause, and predict.

Answer Explained

Rollback Leaves Asha in Mumbai

Asha with Mumbai. Run the script, and rollback discards both pending changes, leaving the state saved before begin. Without rollback, delete without where would remove every row. Updating without where also targets every row, even if that was accidental. The filter determines scope, while the transaction determines which pending changes survive. Read both before executing data changes.

Key Takeaways

Read Every Part Before Running

Recognize the statement's keywords, identifiers, literals, clauses, and delimiters. Create builds structure; insert adds records; ordinary select reads them; update changes values; delete removes rows. Check where before a change, and understand the transaction boundary that surrounds it. Read errors from description to location, fix one cause, and rerun the corrected statement.

About Database Programming at UPI Study

Database Programming (Computer Science 381) is a self-paced online course of 76 video lessons in 12 chapters, from database applications, SQL setup, schema planning and normalization to keys and constraints, data types, filtering and sorting, joins, subqueries, views, indexes, ROLLUP and PIVOT, regular expressions and database security. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: Database Fundamentals vs Database Programming

Why take it here

Why students take Database Programming with UPI Study

Write the SQL behind every appDatabase Programming teaches SQL in MySQL and SQL Server side by side: designing and normalizing tables, keys and constraints, data types, inserting, updating and deleting rows, filtering, grouping, joins, subqueries, views, indexes, transactions, and protecting data from SQL injection. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Database Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About SQL Command Essentials: The Must-Know Statements

What are the parts of a SQL statement?
A SQL statement is built from keywords, identifiers, literals, clauses, and delimiters. In SELECT first_name FROM customers WHERE city = 'Pune'; the words SELECT, FROM, and WHERE are keywords, first_name and customers are identifiers, and 'Pune' is a text literal. Each keyword with its details forms a clause. Commas separate list items, single quotes surround text, and the semicolon ends the statement.
How do you write comments in SQL?
Use two dashes for an end-of-line comment, and use /* to open and */ to close a block comment that can span several lines. In MySQL, put a space after the two dashes, as in -- note. MySQL also accepts a hash sign for line comments, but SQL Server does not. Take care when commenting out part of a data-changing statement, because removing its filter broadens what it changes.
Is SQL case-sensitive?
SQL keywords are not case-sensitive in MySQL, SQL Server, or SQLite, so select and SELECT mean the same thing. Identifiers and text comparisons are separate issues. MySQL table-name behavior depends on the platform and configuration, while SQL Server follows the relevant collation. A collation also decides whether 'Pune' and 'pune' compare as equal, so write names exactly as they were created.
How do you fix a SQL error message?
Read the error description first, then its location, and fix one cause before rerunning. A message such as SQLite's no such table: custmers points to a misspelled identifier rather than broken grammar. For true syntax errors, inspect the reported spot and the token just before it, since a missing comma often confuses the engine at the next value. Also check paired quotes and parentheses and matching column and value counts.

About the Database Programming course

How many college credits is Database Programming?
Database Programming (Computer Science 381) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Database Programming cost and what is included?
$250, paid once, with lifetime access: all 76 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Database Programming take?
It is self-paced with no deadlines. The 76 lessons total about 11 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Database Programming.

76 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Updated

Database Programming
3 credits · NCCRS
Enroll →