Introduction Flashcards
(17 cards)
SQL, which stands for Structured Query Language, is a programming language that is used to communicate with and manage databases.
Data Definition Language (DDL)
It lets you to create, alter, or delete databases and their related objects like tables, views, etc. Commands include CREATE, ALTER, DROP, and TRUNCATE.
Data Manipulation Language (DML)
It lets you manage data within database objects. These commands include SELECT, INSERT, UPDATE, and DELETE.
Data Control Language (DCL)
It includes commands like GRANT and REVOKE, which primarily deal with rights, permissions and other control-level management tasks for the database system.
What’s a database?
A database is an organized collection of data.
The SELECT first_name, FROM employees, and WHERE are clauses in the SQL statement. Some clauses are mandatory e.g., the SELECT and FROM clauses whereas others are optional such as the WHERE clause.
Each command is composed of tokens that can be literals, keywords, identifiers, or expressions. Tokens are separated by space, tabs, or newlines.
Literals
Literals are explicit values which are also known as constants. SQL provides three kinds of literals: string, numeric, and binary.
String literal consists of one or more alphanumeric characters surrounded by single quotes
50 is a number. However, if you surround it with single quotes e.g., ‘50’, SQL treats it as a string literal.
SQL is case sensitive with respect to string literals, so the value ‘John’ is not the same as ‘JOHN’
Numeric literals are the integer, decimal, or scientific notation, for example:
200
-5
6.0221415E23
SQL represents binary value using the notation x’0000’, where each digit is hexadecimal value
Keywords
SQL has many keywords that have special meanings such as SELECT, INSERT, UPDATE, DELETE, and DROP. These keywords are the reserved words, therefore, you cannot use them as the name of tables, columns, indexes, views, stored procedures, triggers, or other database objects.
Identifiers
Identifiers refer to specific objects in the database such as tables, columns, indexes, etc. SQL is case-insensitive with respect to keywords and identifiers.
When parsing SQL statements with comments, the database engine ignores the characters in the comments.
A comment is denoted by two consecutive hyphens ( –) that allow you to comment the remaining line.
– employees with low salary
To document the code that can span multiple lines, you use the multiline C-style notation ( /**/)
/* increase 5% for employees whose salary is less than 3,000 */