Chapter 2 : Getting Started with the SELECT Statement Flashcards
What are the forms of aliasing an attribute in T-SQL?
The forms are AS , , and = .
What is an irregular identifier?
An identifier that does not follow the rules for formatting identifiers; for example, it starts with a digit, has an embedded space, or is reserved T-SQL keyword.
What is the importance of the ability to assign attribute aliases in T-SQL? (Choose all that apply.)
A) The ability to assign attribute aliases is just an aesthetic feature.
B) An expression that is based on computation results in no attribute names unless you assign one with an alias, and this is not relational. C
C) T-SQL requires all result attributes of a query to have names.
D) Using attribute aliases, you can assign your own name to a result attribute if you need it to be different than the source attribute name. C
A) The ability to assign attribute aliases is just an aesthetic feature.
§ Attribute aliasing allows you to meet relational requirements, so it’s certainly more than an aesthetic.
B) An expression that is based on computation results in no attribute names unless you assign one with an alias, and this is not relational. C
§ The relational model requires that all attributes have names.
C) T-SQL requires all result attributes of a query to have names.
§ T-SQL allows a result attribute to be without a name when the expression is based on a computation without an alias.
D) Using attribute aliases, you can assign your own name to a result attribute if you need it to be different than the source attribute name. C
§ You can assign your own name to a result attribute by using an alias.
What are the mandatory clauses in a SELECT query, according to T-SQL A) The FROM AND SELECT clause B) The SELECT and WHERE clause C) The SELECT clause D) The FROM and WHERE clause
A) The FROM AND SELECT clause
§ The FROM and SELECT clause are mandatory in a SELECT query according to Standard SQL but not T-SQL.
B) The SELECT and WHERE clause
§ The WHERE clause is optional in T-SQL.
C) The SELECT clause C
§ According to T-SQL, the only mandatory clause is the SELECT clause.
D) The FROM and WHERE clause
§ The FROM and WHERE clause are both optional in T-SQL
Which of the following practices are considered bad practices? (Choose all that apply.)
A) Aliasing columns by using the AS clause
B) Aliasing tables by using the AS clause
C) Not assigning column aliases when the column is a result of a computation
D) Using * in the SELECT list
A) Aliasing columns by using the AS clause
§ Aliasing columns with the AS clause is standard and considered a best practice.
B) Aliasing tables by using the AS clause
§ Aliasing tables with the AS clause is standard and considered a best practice.
C) Not assigning column aliases when the column is a result of a computation C
§ Not aliasing a column that is a result of a computation is nonrelational and is considered a bad practice.
D) Using * in the SELECT list C
§ Using * in the SELECT list is considered a bad practice.
The identity column property
A property that automatically generates keys in an attribute of a numeric type with a scale of 0; namely, any integer type (TINYINT, SMALLINT, INT, BIGINT) or NUMERIC/DECIMAL with a scale of 0.
The sequence object
An independent object in the database from which you can obtain new sequence values. Like identity, it supports any numeric type with a scale of 0. Unlike identity, it’s not tied to a particular column; instead, as mentioned, it is an independent object in the database. You can also request a new value from a sequence object before using it. There are a number of other advantages over identity that will be covered in Chapter 11.
Non sequential GUIDs
You can generate non sequential global unique identifiers to be stored in an attribute of a UNIQUEIDENTIFIER type. You can use the T-SQL function NEWID to generate a new GUILD, possibly invoking it with a default expression attached to the column. You can also generate one from anywhere - for example, the client - by using an application programming interface (API) that generates a new GUID. The GUIDs are guaranteed to be unique across space and time.
Sequential GUIDs
You can generate sequential GUIDs within the machine by using the T-SQL function NEWSEQUENTIALID.
Custom solutions
If you do not want to use the built-in tools that SQL Server provides to generate keys, you need to develop your own custom solution. The data type for the key depends on your solution.
Would you use the type FLOAT to represent a product unit price?
No, because FLOAT is an approximate date type and cannot represent all values precisely.
What is the difference between NEWID and NEWSEQUENTIALID?
The NEWID function generates GUID values in random order, whereas the NEWSEQUENTIAL ID function generates GUILDs that increase in a sequential order.
Which function returns the current date and time values as a DATETIME2 type?
The SYSDATETIME functions
When concatenating character strings, what is the difference between the plus (+) operator and the CONCAT function?
The + operator by default yields a NULL result on NULL input, whereas the CONCAT function treats NULLs as empty strings.
Why is it important to use the appropriate type of attributes?
A) Because the type of your attribute enables you to control the formatting of the values.
B) Because the type constrains the values to a certain domain of supported values
C) Because the type prevents duplicates.
D) Because the type prevents NULLs.
Why is it important to use the appropriate type of attributes?
A) Because the type of your attribute enables you to control the formatting of the values.
§ Formatting isn’t a responsibility of the type or the data layer in general; rather, it is the responsibility of the presentation layer.
B) Because the type constrains the values to a certain domain of supported values C.
§ The type should be considered a constraint because it limits the values allowed.
C) Because the type prevents duplicates.
§ The type itself doesn’t prevent duplicates. If you need to prevent duplicates, you use the primary key or unique constraint.
D) Because the type prevents NULLs.
§ A type doesn’t prevent NULLs. For this, you use a NOT NULL constraint.