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
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Database Programming.
Lesson complete
Earn the 3 college credits for Database Programming
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Installing Your Database Environment — MySQL and SQL Server Express Setup Guide →← 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 →
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.
Enroll now → Course details Download the syllabus All Computer Science courses Every credit course with PRO →
Why take it here
Why students take Database Programming with UPI Study
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.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →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?
How do you write comments in SQL?
Is SQL case-sensitive?
How do you fix a SQL error message?
About the Database Programming course
How many college credits is Database Programming?
How much does Database Programming cost and what is included?
Which universities accept UPI Study credits?
How long does Database Programming take?
How are the exams done?
How do my credits reach my college?
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
3 credits · NCCRSEnroll →