Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

bit decimal numeric: Giải thích tổng thể

Uploaded by

Anh Hoai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

bit decimal numeric: Giải thích tổng thể

Uploaded by

Anh Hoai
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Câu hỏi 1Chính xác

Which of these data types is an approximate numeric?


real
bit
decimal
numeric
Giải thích tổng thể
Correct Answer: real

Reason:

 The real data type is considered an approximate numeric data type in SQL. It
is used to store floating point numbers where exact precision is not required
but a close approximation is sufficient. real can represent a wide range of
values more compactly than exact numeric types, but with the potential for
rounding errors.
 Example: real is suitable for scientific calculations where extremely large or
small values are common, but absolute precision is not critical.

Incorrect Answers and Reasons:

 bit:
 Incorrect because the bit data type is used to store binary data in the
form of 1 (true) or 0 (false). It is not used for numeric calculations
where approximate or exact values are concerned.
 decimal:
 Incorrect as decimal is an exact numeric data type that provides
precise numerical storage and calculations. It is used when it is
important to preserve exact precision, such as with monetary data.
 numeric:
 Incorrect because numeric is also an exact numeric data type, similar
to decimal . It allows for precise storage of numbers with a fixed
number of decimal places, making it inappropriate for approximations.
Câu hỏi 2Chính xác
What is the result of this query?
1. SELECT 1 / 2 AS Result;
2. 0.5
3. error
4. 0
5. 2
Giải thích tổng thể
Correct Answer: 0

Reason:

 In SQL, when both operands in a division are integers, the operation performs
integer division. Integer division truncates any fractional part and returns the
integer portion of the quotient. Since 1 / 2 is less than 1, the result is
truncated to 0.
 Example: This behavior is consistent across many SQL databases, where the
precise outcome of an arithmetic operation depends on the data types of the
operands involved. To obtain a fractional result, at least one operand must be
of a decimal or floating-point type.
Câu hỏi 3Chính xác
What is the result of this query?
1. SELECT 123+'123' AS Result;
2. error
3. '123''123'
4. 123123
5. 246
Giải thích tổng thể
Correct Answer: 246

Reason:

 In SQL, when you add an integer to a string that can be implicitly converted to
a numeric type, SQL Server performs an implicit conversion and adds the
numeric values. Here, '123' (a string) can be converted to 123 (an integer),
and adding it to 123 (the initial integer) results in 246 .
 Example: This demonstrates SQL's ability to perform implicit type conversion
when possible, facilitating arithmetic operations between numeric strings and
actual numeric data types, leading to the sum of the two values.
Câu hỏi 4Chính xác
. What is the result of this query?
1. SELECT 123+'abc' AS Result;
2. 123abc
3. 123'abc'
4. '123abc'
5. error

Giải thích tổng thể


Correct Answer: error

Reason:

 In SQL, attempting to add an integer ( 123 ) to a non-numeric string ( 'abc' )


results in a type conversion error because the string cannot be implicitly
converted to a numeric type for the addition operation. SQL Server and other
SQL-based databases require compatible types for arithmetic operations, and
in this case, the operation fails due to incompatible types.
 Example: This highlights the importance of ensuring data type compatibility in
expressions. Unlike concatenation operations that might implicitly convert
numeric values to strings in some contexts, adding a numeric value to a non-
convertible string value leads to an error.
Câu hỏi 5Chính xác
What is the result of this query?
1. SELECT 123+'123' AS Result;

123'123'
error
246
123123
Giải thích tổng thể
Correct Answer: 246

Reason:

 In SQL, when you attempt to add an integer ( 123 ) to a string that represents a
numeric value ( '123' ), the database engine typically performs an implicit conversion
of the string to a numeric type and then completes the addition. Therefore, 123 +
123 results in 246 .
 Example: This behavior illustrates SQL's ability to implicitly convert strings to
numeric values for arithmetic operations, provided the string can be accurately
converted to a number.

Câu hỏi 1Không chính xác


Which is the best approach to update the last name of the student Donette Figgins to Smith
Correct answer
UPDATE Students SET last_name = 'Smith' WHERE email =
'dfiggins@rouxacademy.com';
UPDATE Students SET last_name = 'Figgins' WHERE email =
'dfiggins@rouxacademy.com';
UPDATE Students SET last_name = 'Figgins' WHERE last_name = 'Smith' AND
first-name = 'Donette';
UPDATE Students SET last_name = 'Smith' WHERE last_name = 'Figgins' AND
first-name = 'Donette';
Giải thích tổng thể
Correct Answer: UPDATE Students SET last_name = 'Smith' WHERE email =
'dfiggins@rouxacademy.com';

Reason:

 This query precisely targets the student by their unique email address, ensuring that
the correct record is updated. By specifying WHERE email =
'dfiggins@rouxacademy.com' , it directly identifies Donette Figgins and updates
her last name to 'Smith'.
 Example: In databases, email addresses often serve as a unique identifier for
individuals, making them a reliable criterion for pinpointing a specific record for
updates.

Incorrect Answers and Reasons:


 UPDATE Students SET last_name = 'Figgins' WHERE email =
'dfiggins@rouxacademy.com';
 Incorrect because it attempts to set the last name back to 'Figgins', which is
already the current last name according to the premise, thus not achieving the
desired update to 'Smith'.
 UPDATE Students SET last_name = 'Figgins' WHERE last_name = 'Smith'
AND first-name = 'Donette';
 Incorrect as this query incorrectly tries to revert the last name from 'Smith' to
'Figgins', opposite to the required update. Additionally, the use of first-
name is syntactically incorrect due to the hyphen.
 UPDATE Students SET last_name = 'Smith' WHERE last_name = 'Figgins'
AND first-name = 'Donette';
 This option contains a syntax error with first-name (should
be first_name if that's the column name), and while it aims to update the last
name to 'Smith', it's less precise without using the unique email identifier,
potentially affecting other students named Donette Figgins if the database does
not enforce unique first and last name combinations. The best practice for
updates is to use the most unique identifier available, which in this case, is the
email address.
Câu hỏi 2Chính xác
To select a random student from the table, which statement could you use?
Your answer is correct
SELECT TOP(1) first_name, last_name FROM Students ORDER BY NEWID();
SELECT TOP(1) RAND(first_name, last_name) FROM Student;
SELECT TOP(1) first_name, last_name FROM Student;
SELECT TOP(1) first_name, last_name FROM RAND(Student);
Giải thích tổng thể
Correct Answer: SELECT TOP(1) first_name, last_name FROM Students ORDER BY
NEWID();

Reason:

 This query utilizes the NEWID() function to generate a unique identifier for each row,
effectively randomizing the order of the students. By then selecting the top row
with SELECT TOP(1) , it retrieves a random student from the table. This is a
commonly used method in SQL Server to select a random record.
 Example: In scenarios where you need to randomly pick a participant for a survey or
a prize draw from a list of students, this query ensures each student has an equal
chance of being selected.

Incorrect Answers and Reasons:

 SELECT TOP(1) RAND(first_name, last_name) FROM Student;


 Incorrect because RAND() does not work in this manner. It generates a random
floating-point number between 0 and 1 and cannot be used directly to order or
select columns.
 SELECT TOP(1) first_name, last_name FROM Student;
 Incorrect as it simply selects the first student based on the default ordering of
the table, which is not random. Without an ORDER BY clause specifying a
random order, the result is predictable based on the table's current ordering.
 SELECT TOP(1) first_name, last_name FROM RAND(Student);
 Incorrect because this syntax is not valid. RAND() generates a random number
and cannot be used to directly operate on a table or influence the selection of
rows in the manner suggested.
Câu hỏi 3Chính xác
What does a RIGHT JOIN ensure?
that only records from the rightmost table will be displayed
that no records from the rightmost table are displayed if the records dont have
corresponding records in the left table
that records from the rightmost table will be displayed only if the records have a
corresponding value in the leftmost table
Your answer is correct
that all records from the rightmost table are represented in the result, even if there are
no corresponding records in the left table
Giải thích tổng thể
Correct Answer: that all records from the rightmost table are represented in the result,
even if there are no corresponding records in the left table

Reason:

 A RIGHT JOIN ensures that all records from the right-hand (rightmost) table are
included in the join results, regardless of whether there are matching records in the
left-hand table. If there's no match found in the left-hand table, the result set will still
include rows from the right-hand table, with nulls in the columns of the left-hand
table where matches are absent.
 Example: If you have a table of employees ( left table ) and a table of departments
( right table ), a RIGHT JOIN would include all departments, even those without
any employees assigned to them, potentially filling employee details with NULLs for
departments without employees.
Câu hỏi 4Chính xác
You execute the following three queries. What is the result?
1. Create table students(id int identity(1000,1), firstname varchar(20),
2. lastname varchar(30));
3. insert into students(firstname,lastname)values('mark','twain');
4. select * from students;

studentid firstname lastname 1 1001 mark twain


studentid firstname lastname 1 1 mark twain
Your answer is correct
studentid firstname lastname 1 1000 mark twain
studentid firstname lastname 1 null mark twain
Giải thích tổng thể
Correct Answer: studentid firstname lastname 1 1000 mark twain

Reason:
 The CREATE TABLE statement includes an IDENTITY column starting at 1000 with an
increment of 1 . This means the first entry into the students table will have
an id of 1000 .
 When the INSERT statement adds 'Mark Twain' to the table, he is assigned the
first id value generated by the IDENTITY specification, which is 1000 .
 Therefore, selecting all records from the students table after this insert will show
Mark Twain with an id of 1000 .

Incorrect Answers and Reasons:

 1 1001 mark twain:


 Incorrect because the identity column starts at 1000 and increments by 1 . The
first inserted row receives the starting value of 1000 , not 1001 .
 1 1 mark twain:
 Incorrect as the id column is defined to start at 1000 , not 1 . This entry does
not reflect the IDENTITY property specified in the table creation.
 1 null mark twain:
 Incorrect because the IDENTITY specification automatically assigns a value to
the id column starting from 1000 and incrementing by 1 for each new row. It
would not result in a null value for the id .
Câu hỏi 5Chính xác
What role does "inventory" play?
1. select bookid, boooktitle, bookauthor,quantityonhand from inventory.books;





you only want to see results from books currently in inventory
Your answer is correct
it instructs the query engine to find the books table in the inventory schema
it instructs the query engine to find the books table in the inventory database
it instructs the query engine to join the books table to the inventory schema
Giải thích tổng thể
Correct Answer: it instructs the query engine to find the books table in the inventory
schema

Reason:

 In the provided query, inventory specifies the schema within the database that
contains the books table. Schemas are used to organize and secure database objects,
such as tables, and can be thought of as containers within a database.
 Example: If you have multiple schemas within a database for different purposes or
departments, specifying inventory.books directs the query to look for
the books table specifically within the inventory schema, ensuring that the correct
table is accessed for the query.

Incorrect Answers and Reasons:


 you only want to see results from books currently in inventory:
 Incorrect because the term inventory in this context does not reflect the
content of the books (i.e., whether they are in stock) but rather indicates the
schema name in the database.
 it instructs the query engine to find the books table in the inventory database:
 Incorrect as inventory here refers to a schema, not a separate database. A
single database can contain multiple schemas.
 it instructs the query engine to join the books table to the inventory schema:
 Incorrect because the query does not imply a join operation between tables and
schemas. Instead, it specifies the location of the books table within
the inventory schema, not a join action.
Câu hỏi 6Chính xác
To remove all of the content from the Students table but keep the schema, which statement
should you use?
Your answer is correct
TRUNCATE TABLE Students;
TRUNCATE * FROM Students;
DROP TABLE Students;
REMOVE * FROM Students;
Giải thích tổng thể

Correct Answer: TRUNCATE TABLE Students;

Reason:

 TRUNCATE TABLE Students; efficiently removes all rows from


the Students table without logging the deletion of each row, making it faster than
a DELETE operation. Importantly, it preserves the table structure (schema), allowing
for future data to be inserted.
 Example: In scenarios requiring a quick reset of table data while maintaining the
table's existence and structure, TRUNCATE TABLE is the optimal choice.

Incorrect Answers and Reasons:

 TRUNCATE * FROM Students;


 Incorrect because this syntax is not valid in SQL. The correct syntax for
truncating a table does not include the asterisk (*) symbol.
 DROP TABLE Students;
 Incorrect as DROP TABLE completely removes the table and its schema from
the database, not just its contents. If you need to use the table again, it must be
recreated.
 REMOVE * FROM Students;
 Incorrect because REMOVE is not a valid SQL keyword for deleting or
truncating data. The correct commands for removing data are DELETE
FROM (for row-wise deletion with conditions) and TRUNCATE TABLE (for
removing all rows quickly while retaining the table structure).
Câu hỏi 7Chính xác
Which is the right query to change the name of the Philosophy Pandas team to the Philosophy
Parrots?
Your answer is correct
UPDATE Students SET team = 'Philosophy Parrots' WHERE team = 'Philosophy
Pandas';
UPDATE Students SET team = Philosophy Parrots WHERE team = Philosophy Pandas;`
UPDATE Students SET team = "Philosophy Parrots" WHERE team = "Philosophy
Pandas";
UPDATE Students SET team = Philosophy Parrots WHERE team = Philosophy
Pandas;
Giải thích tổng thể
Correct Answer: UPDATE Students SET team = 'Philosophy Parrots' WHERE team =
'Philosophy Pandas';

Reason:

 This query correctly uses the UPDATE statement to modify the team column values in
the Students table. It specifies changing the team name from 'Philosophy Pandas' to
'Philosophy Parrots' for all relevant records, using single quotes ( ' ) to enclose string
literals, which is the correct syntax in SQL.
 Example: This command ensures that all student records previously associated with
the 'Philosophy Pandas' team are accurately updated to reflect their new team name,
'Philosophy Parrots', maintaining data integrity and consistency within the database.

Incorrect Answers and Reasons:

 UPDATE Students SET team = Philosophy ParrotsWHERE team =Philosophy


Pandas;`
 Incorrect due to missing single quotes around the string literals and a missing
space before WHERE , leading to syntactical errors. SQL requires string values
to be enclosed in single quotes.
 UPDATE Students SET team = "Philosophy Parrots" WHERE team =
"Philosophy Pandas";
 While some SQL database systems may allow double quotes for string literals,
the standard and widely supported method is to use single quotes for string
values. Double quotes are typically used for identifiers (like column and table
names), not string literals.
 UPDATE Students SET team = Philosophy Parrots WHERE team = Philosophy
Pandas;
 Incorrect because it lacks single quotes around the string literals, making the
syntax invalid. Without quotes, SQL interprets Philosophy
Parrots and Philosophy Pandas as identifiers (e.g., column names) rather
than string values.

Câu hỏi 8Không chính xác


You run this series of statements. What is the final result?
1. CREATE TABLE MyTable (MyValue int);
2. INSERT INTO MyTable VALUES (1);
3. WHILE (SELECT MyValue FROM MyTable) < 5
4. BEGIN
5. UPDATE My Table SET MyValue = MyValue + 1;
6. END;
7. SELECT MyValue AS Result FROM MyTable;

Your answer is incorrect


5
Correct answer
error
1
6
Giải thích tổng thể
Correct Answer: error

Reason:

 The given query will result in an error due to a syntax mistake in


the UPDATE statement: UPDATE My Table SET MyValue = MyValue + 1; contains
a space between "My" and "Table", which is incorrect syntax as table names cannot
have spaces unless enclosed in brackets or quotes (depending on the SQL dialect).
Therefore, the script will not execute as intended, and an error will be raised at this
point.
 Example: Correct syntax for referring to table names involves either no spaces
(e.g., MyTable ) or, if spaces are required, enclosing the name in square brackets or
quotes (e.g., [My Table] or "My Table" in some SQL dialects). Without this
correction, SQL does not recognize the intended table name, leading to an execution
error.
Câu hỏi 9Chính xác
Which statement could you use to select a random student from this table?





Your answer is correct
SELECT TOP(1) first_name, last_name FROM Students ORDER BY NEWID();
SELECT TOP(1) RAND(first_name, last_name) FROM Student;
SELECT TOP(1) first_name, last_name FROM Student;
SELECT TOP(1) first_name, last_name FROM RAND(Student);
Giải thích tổng thể
Correct Answer: SELECT TOP(1) first_name, last_name FROM Students ORDER BY
NEWID();

Reason:

 This query correctly uses the NEWID() function to generate a unique identifier for
each row, effectively randomizing the order of the students. By then selecting the top
row with SELECT TOP(1) , it retrieves a random student from the table. This method
is widely recognized for its effectiveness in randomly selecting rows from a table in
SQL Server.
 Example: This approach is particularly useful in scenarios where you need to
randomly pick a student for a task or as a sample from a larger dataset, ensuring each
student has an equal chance of being selected.
Lĩnh vực
Random
Câu hỏi 10Chính xác
What output will the following SQL sequence produce? Assume that the tables have been
created and all the columns exist.
1. INSERT INTO Account (acct,bal) VALUES ('12345', 100);
2. UPDATE Account SET bal=bal+100;
3. BEGIN;
4. UPDATE Account SET bal=bal+100.
5. ROLLBACK;
6. SELECT bal FROM Account WHERE acct='12345';
7. );

100
Your answer is correct
200
300
You will get an error because ROLLBACK deletes the row that was update
Giải thích tổng thể
Correct Answer: 200

Reason:

 After the initial INSERT statement, the balance ( bal ) for account '12345' is set to
100.
 The first UPDATE statement adds 100 to the balance, making it 200.
 The sequence that follows attempts to begin a transaction and then apply another
update to add 100 more to the balance. However, a ROLLBACK is called immediately
after, which undoes the second update.
 Since the ROLLBACK reverts the changes made by the second update, the balance
remains as it was after the first update, which is 200.
 Example: This illustrates the use of transactions to manage data changes, allowing
changes to be reverted if necessary. The ROLLBACK command undoes the second
update, leaving the balance at the state it was before the transaction began.

Incorrect Answers and Reasons:

 100:
 Incorrect because the first update, which is outside of the transaction and not
affected by the ROLLBACK , successfully adds 100 to the initial balance.
 300:
 Incorrect as the second update that would have brought the balance to 300 is
reverted by the ROLLBACK .
 You will get an error because ROLLBACK deletes the row that was updated:
 Incorrect because ROLLBACK does not delete rows; it reverts the database to its
previous state before the transaction began. The row updated before
the BEGIN statement is unaffected by the ROLLBACK .
Câu hỏi 11Chính xác
The Marketing department wants to send an email to each member of the Humanities
department. Based on the table below, which query gives them the first name and email
address of each member of that department?
SELECT first_name, email FROM Students WHERE department = Humanities;
SELECT first_name, email FROM Students WHERE department = "Humanities";
Your answer is correct
SELECT first_name, email FROM Students WHERE department = 'Humanities';
SELECT 'first_name', 'email' FROM 'Students' WHERE 'department' =
"Humanities";
Giải thích tổng thể
Correct Answer: SELECT first_name, email FROM Students WHERE department =
'Humanities';

Reason:

 This query correctly uses single quotes ( ' ) to specify the string literal 'Humanities' in
the WHERE clause, which is the standard way to denote string literals in SQL. It selects
the first_name and email from the Students table for entries where
the department column matches 'Humanities'.
 Example: This approach ensures that the marketing department can accurately target
communications to students belonging to the Humanities department, utilizing the
correct syntax for string comparison in SQL.

Incorrect Answers and Reasons:

 SELECT first_name, email FROM Students WHERE department = Humanities;


 Incorrect because Humanities without quotes is interpreted as an identifier
(like a column name) rather than a string value. The query would fail because
there is no column named Humanities .
 SELECT first_name, email FROM Students WHERE department =
"Humanities";
 Incorrect in the context of standard SQL (particularly T-SQL for SQL Server),
which typically uses single quotes for string literals. Double quotes are used to
identify database objects, not string values.
 SELECT 'first_name', 'email' FROM 'Students' WHERE 'department' =
"Humanities";
 Incorrect because placing single quotes around column and table names turns
them into string literals, not references to the database schema. This would not
execute as intended, as it does not correctly specify the columns or table in the
database.

Câu hỏi 12Không chính xác


Which statement deletes a table named Inventory from the Products database?
1. DROP TABLE Products.Inventory;

Correct answer
1. USE Products;
2. DROP TABLE Inventory;

1. USE Products;
2. DELETE Inventory;

Your answer is incorrect


1. USE Products.Inventory;
2. DROP TABLE Inventory;

Giải thích tổng thể


Correct Answer: USE Products; DROP TABLE Inventory;

Reason:

 This sequence of commands first switches the context to the Products database using
the USE Products; statement. Then, it executes the DROP TABLE
Inventory; command to delete the Inventory table within that database. This is the
standard approach to specify the database where a table should be dropped in systems
like SQL Server.
 Example: When needing to remove a table entirely from a specific database, it's
crucial to ensure that the database context is correctly set with USE
<database_name>; before executing the DROP TABLE command.

Incorrect Answers and Reasons:

 DROP TABLE Products.Inventory;


 Incorrect because, although this syntax attempts to specify the database and
table directly in the DROP TABLE command, it's not the standard approach for
all SQL database systems. The correctness of this syntax can depend on the
specific SQL dialect being used.
 USE Products; DELETE Inventory;
 Incorrect as DELETE is used to remove rows from a table, not to drop the table
itself. Additionally, the syntax DELETE Inventory; is not valid for deleting a
table.
 USE Products.Inventory; DROP TABLE Inventory;
 Incorrect because USE is followed by a database name, not a schema or table
qualifier. This suggests an attempt to set the context to a specific schema
within a database, which is not how the USE statement functions.
Quay lại phần tổng quan về kết quảCuộn trở lại đầu trang
Làm lại bài kiểm tra
Tiếp tục
Nội dung khóa học
Bài kiểm tra thực hành
 Đã hoàn thành bài giảng. Không thể thay đổi tiến độ cho mục này.
Bắt đầu
Bài kiểm tra thực hành 1: Basic SQL Commands and Concepts
 Đã hoàn thành bài giảng. Không thể thay đổi tiến độ cho mục này.
Bắt đầu
Bài kiểm tra thực hành 2: Query Writing and Data Manipulation
 Đã hoàn thành bài giảng. Không thể thay đổi tiến độ cho mục này.
Bắt đầu
Bài kiểm tra thực hành 3: Advanced SQL Features and Techniques
 Đã hoàn thành bài giảng. Không thể thay đổi tiến độ cho mục này.
Bắt đầu
Bài kiểm tra thực hành 4: Data Types and Values
 Đã hoàn thành bài giảng. Không thể thay đổi tiến độ cho mục này.
Bắt đầu
Bài kiểm tra thực hành 5: Table and Database Management
Tổng quan
Hỏi đápCâu hỏi và câu trả lời
Ghi chú
Thông báo
Đánh giá
Công cụ học tập

You might also like