WEEK 4 Flashcards
(22 cards)
Answer: SQL stands for Structured Query Language and is a query language used to manage and manipulate relational databases.
Question: What is SQL?
Question: What is the difference between DDL and DML?
Answer: DDL stands for Data Definition Language and is used to define the structure and schema of a database. DML stands for Data Manipulation Language and is used to manipulate the data stored in a database.
Question: What does the SQL statement “SELECT * from product;” do?
Answer: This SQL statement selects all columns and rows from the “product” table.
Question: What does the * symbol represent in the SQL statement “SELECT * from product;”?
.
Answer: The * symbol represents all columns in the specified table
Question: How can you select only specific columns in a SQL query?
Answer: You can specify the column names in the SELECT statement instead of using the * symbol.
Question: What is the purpose of the “–” symbol in SQL?
Answer: The “–” symbol is used to indicate a comment in SQL code.
Question: What are logical operators in SQL?
Answer: Logical operators are used in SQL to combine conditions in a query. The two most common operators are “AND” and “OR”.
Question: How can you concatenate two columns in a SQL query?
Answer: You can concatenate two columns by using the + operator in between them, like this: SELECT CUS_FNAME +’ ‘+ CUS_LNAME FROM CUSTOMER;
Question: What is the purpose of the DISTINCT keyword in SQL?
Answer: The DISTINCT keyword is used to remove duplicates from the results of a query and only show unique values.
Question: How can you order the results of a SQL query?
Answer: You can use the ORDER BY keyword followed by the column name to sort the results of a query. By default, the results are sorted in ascending order, but you can add the “DESC” keyword to sort in descending order.
Question: What is the purpose of the BETWEEN keyword in SQL?
Answer: The BETWEEN keyword is used to filter results within a specified range of values.
What is DML?
.
Answer: DML is a data manipulation language used to insert, update, delete, and retrieve information
What is DDL?
Answer: DDL is a data definition language used to create objects (tables, indexes, views) and access rights (users).
What is TCL?
Answer: TCL is a transaction control language.
What is DCL?
Answer: DCL is a data control language used for user permission - who can do what.
What are some data types?
Answer: Data types include character (string), numeric (int, float), date/time, boolean (yes/no), and GUID.
What is the syntax for the SELECT keyword?
Answer: The syntax for the SELECT keyword is SELECT (data fields) FROM (tablename).
What is an alias in SQL?
Answer: An alias in SQL is used to make field names prettier. It is a syntax that allows you to rename a column in a table with another name.
To create a table, you
will need:
- A table name
- Names for all
columns - Data type for each
column - Applicable
constraints
DDL (Data Definition Language) commands:
NOT NULL
PRIMARY KEY
FORIEGN KEY
DEFAULT
CHECK
CREATE: used to create a new database object such as a table, index, view, or stored procedure.
ALTER: used to modify the structure of an existing database object.
DROP: used to delete an existing database object.
TRUNCATE: used to delete all the data from a table without deleting the table structure.
RENAME: used to rename an existing database object.
GRANT: used to grant specific privileges to a user or role.
REVOKE: used to revoke privileges that were previously granted.
DML (Data Manipulation Language) commands:
SELECT: used to retrieve data from a database table.
INSERT: used to insert new data into a database table.
UPDATE: used to modify existing data in a database table.
DELETE: used to delete data from a database table.
MERGE: used to combine data from two tables into a single table.
CALL: used to execute a stored procedure or function.
LOCK: used to lock a table or row to prevent other users from modifying the data.
Character: This data type is used to store strings of characters, such as names, addresses, and other textual data. The maximum length of a character data type is determined by the database system.
Numeric: This data type is used to store numeric data, such as integers or decimal numbers. There are different types of numeric data types in SQL, such as INTEGER, SMALLINT, BIGINT, DECIMAL (L,D), and FLOAT.
Date/time: This data type is used to store date and time data. The SQL standard defines two data types for date/time data: DATE for storing dates and TIMESTAMP for storing both dates and times.
Character: This data type is used to store strings of characters, such as names, addresses, and other textual data. The maximum length of a character data type is determined by the database system.
Numeric: This data type is used to store numeric data, such as integers or decimal numbers. There are different types of numeric data types in SQL, such as INTEGER, SMALLINT, BIGINT, DECIMAL, and FLOAT.
Date/time: This data type is used to store date and time data. The SQL standard defines two data types for date/time data: DATE for storing dates and TIMESTAMP for storing both dates and times.