Docsity

Lesson 3 Basic SQL.docx.....Lesson 3 Basic SQL.docx, Exams of Nursing

Toggle sidebar
bg1
Lesson 3 Basic SQL
Define data definition language. - correct answer -
Includes commands to create database objects such as tables, indexes, and view,
as well as commands to define access rights to those database objects. It changes
stored data but not the data objects. The commands include things like: CREATE
TABLE, NOT NULL, UNIQUE, etc.
Data manipulation language. - correct answer - Data
manipulation language: Includes commands to insert, update, delete, and retrieve
data within the database tables. It refers to a language that describes the database
structures. The commands include things like: GROUP BY, DESCRIBE, DELETE,
WHERE, etc.
Before you can create a new RDBMS, you must complete two tasks: - correct answer
- Create the database structure
- Create the tables that will hold the end-user data
Define a database schema. - correct answer - A
schema is a logical group of database objects - such as tables and indexes - that are
related to each other. The schema usually belongs to a single user or application. A
single database can hold multiple schemas that belong to different users or
applications.
Depict what the INSERT command looks like when entering numeric and null values.
- correct answer - INSERT INTO PRODUCT
VALUES ('BRT-345', 'Titanium drill bit', 45, 64, NULL);
How do you save table changes? - correct answer -
COMMIT [WORK] or COMMIT; (saves everything)
Define the SELECT command. - correct answer - Used
to list the contents of a table. The syntax of the SELECT command is as follows:
SELECT columnlist FROM tablename
pf3
pf4
pf5

Partial preview of the text

Download Lesson 3 Basic SQL.docx.....Lesson 3 Basic SQL.docx and more Exams Nursing in PDF only on Docsity!

Lesson 3 Basic SQL

Define data definition language. - correct answer - Includes commands to create database objects such as tables, indexes, and view, as well as commands to define access rights to those database objects. It changes stored data but not the data objects. The commands include things like: CREATE TABLE, NOT NULL, UNIQUE, etc. Data manipulation language. - correct answer - Data manipulation language: Includes commands to insert, update, delete, and retrieve data within the database tables. It refers to a language that describes the database structures. The commands include things like: GROUP BY, DESCRIBE, DELETE, WHERE, etc. Before you can create a new RDBMS, you must complete two tasks: - correct answer

  • Create the database structure
  • Create the tables that will hold the end-user data Define a database schema. - correct answer - A schema is a logical group of database objects - such as tables and indexes - that are related to each other. The schema usually belongs to a single user or application. A single database can hold multiple schemas that belong to different users or applications. Depict what the INSERT command looks like when entering numeric and null values.
  • correct answer - INSERT INTO PRODUCT VALUES ('BRT-345', 'Titanium drill bit', 45, 64, NULL); How do you save table changes? - correct answer - COMMIT [WORK] or COMMIT; (saves everything) Define the SELECT command. - correct answer - Used to list the contents of a table. The syntax of the SELECT command is as follows: SELECT columnlist FROM tablename

How do you restore table contents and delete table rows? - correct answer

  • ROLLBACK; and the DELETE syntax is: DELETE FROM tablename [WHERE conditionlist]; What type of query is always executed first? - correct answer
  • Subquery aka nested or inner query What does a conditional restriction look like? - correct answer
  • SELECT columnlist FROM tablelist [WHERE conditionlist]; The restriction is always placed right by the WHERE clause. You can add conditionals like =, <>, etc. What command changes a table and what options are available to make specified changes in conjunction with that initial command? - correct answer
  • The command is ALTER TABLE and the options include ADD, MODIFY, and DROP (which all correlate to columns/attributes). Define how you would add or modify columns. - correct answer
  • ALTER TABLE tablename {ADD | MODIFY} ( columnname datatype [ {ADD | MODIFY} columnname datatype ] ); Define how you would remove a column or table constraint. - correct answer
  • ALTER TABLE tablename DROP {PRIMARY KEY | COLUMN columnname | CONSTRAINT constraintname }; Depict how you would remove a column. - correct answer
  • ALTER TABLE tablename DROP COLUMN COLUMNNAME;

FROM tablelist [WHERE conditionlist ] [ORDER BY columnlist [ASC | DESC] ]; Define what a cascading order sequence is. - correct answer

  • Multileveled ordered sequence is known as a cascading order sequence and it is created by listing several attributes, separated by commas, after the ORDER BY clause. Define the DISTINCT clause. - correct answer - A simple listing (SELECT) is not very useful if the table contains several thousand rows and you have to sift through the vendor codes manually. The DISTINCT clause produces a list of only those values that are different from one another, example: SELECT DISTINCT V_CODE FROM PRODUCT; Define the COUNT function. - correct answer - Uses one parameter within parentheses, generally a column name such as COUNT(V_CODE) or COUNT(P_CODE). The parameter can also be an expression, i.e.; COUNT(DISTINCT V_CODE) or COUNT(P_PRICE+10). Define the outer query. - correct answer - Executed last - remember that the outer query is always the first SQL command you encounter and in this case it is SELECT. The following command sequence - note that the inner query first finds the maximum price value, which is stored in memory. Because the outer query now has a value to which to compare each P_PRICE value, the query executes properly. SELECT P_CODE, P_DESCRIPT, P_PRICE FROM PRODUCT WHERE P_PRICE = (SELECT MAX(P_PRICE) FROM PRODUCT); Define the AVG function. - correct answer - Similar to those of MIN and MAX and is subject to the same operating restrictions. Example: SELECT AVG(P_PRICE) FROM PRODUCT;

Define GROUP BY clause. - correct answer - Generally used when you have attribute columns combined with aggregate functions in the SELECT statement. Valid only when used in conjunction with one of the SQL aggregate functions, such as COUNT, MIN, MAX, AVG, and SM. Define HAVING clause. - correct answer - Operates like the WHERE clause in the SELECT statement, however, the WHERE clause applies to columns and expressions for individual rows, while the HAVING clause is applied to the output of a GROUP BY operation. Example: SELECT V_CODE, SUM(P_QOH * P_PRICE) AS TOTCOST FROM PRODUCT GROUP BY V_CODE HAVING (SUM(P_QOH * P_PRICE) > 500) ORDER BY SUM(P_QOH * P_PRICE) DESC; How do you join database tables? - correct answer - You must simply list the tables in the FROM clause of the SELECT statement. The DBMS will create the Cartesian product of every table in the FROM clause. However, to get the correct result-that is, a natural join-you must select only the rows in which the common attribute values match. To do this, use the WHERE clause to indicate the common attributes used to link the tables; this WHERE clause is sometimes referred to as the join condition. Explain the difference between an ORDER BY clause and a GROUP BY clause. - correct answer An ORDER BY clause has no impact on which rows are returned by the query, it simply sorts those rows into the specified order. A GROUP BY clause does impact the rows that are returned by the query. A GROUP BY clause gathers rows into collections that can be acted on by aggregate functions. What is the difference between the COUNT aggregate function and the SUM aggregate function? - correct answer COUNT returns the number of values without regard to what the values are. SUM adds the values together and can only be applied to numeric values. What is a recursive join? - correct answer A recursive join is a join in which a table is joined to itself.