SQL test answer – Upwork

DB
Content Protection by DMCA.com

Question 1: Which of the following operators can be used to check if a column contains NULL value?
Operator nào dưới đây được sử dụng để kiểm tra ràng buộc cột có chứa giá trị NULL

  1. EXISTS
  2. IS NULL
  3. =
  4. <>
  5. NOT

Answer: Đáp án B (IS NULL), kiểm tra ràng buộc NULL thì chỉ nên sử dụng IS NULL

Question 2: Which of the following is not a DDL statement?
Cái nào dưới đây không là DDL statement

  1. CREATE TABLE
  2. DROP TABLE
  3. TRUNCATE TABLE
  4. INNER JOIN

Answer: Đáp án D (INNER JOIN). Loại 3 đáp án A,B,C
Chú ý: DDL (Data Definition Language) let you to perform these tasks:

  • Create, alter, and drop schema objects
  • Grant and revoke privileges and roles
  • Analyze information on a table, index, or cluster
  • Establish auditing options
  • Add comments to the data dictionary

Question 3: Which of the following is the correct syntax for writing sub query?
SQL nào là đúng khi viết sub query?

1. SELECT sub.*
	FROM (
		SELECT *
		FROM abc
		WHERE day = 'Friday'
	)
WHERE sub.resolution = 'NONE'
2. SELECT *
	FROM (
		SELECT *
		FROM abc
		WHERE day = 'Friday'
	)
   WHERE resolution = 'NONE'
3. SELECT sub.*
	FROM (
		SELECT *
		FROM abc
		WHERE day = 'Friday'
	) sub
WHERE sub.resolution = 'NONE'

Answer: Đáp án C. Loại A do không có alias sub, loại B do không rõ item resolution lấy từ đâu.

Question 3: Which of the following can be used with LIKE operator?

  1. %
  2. =
  3. >
  4. <

Answer: Đáp án A (%).

Question 4: Consider two tables a and b, having only one column each and having these values:
A = [0,1,2,3,4,5]
B = [5,6,7,8,9,10]
The result of the UNION ALL operator on these tables will be?

Kết quả khi thực hiện UNION ALL A và B là?

  1. [0,1,2,3,4,5,6,7,8,9,10]
  2. [5]
  3. [0,1,2,3,4,5,5,6,7,8,9,10]
  4. None of the above.

Answer: Đáp án C. Lưu ý UNION ALL không loại bỏ trùng lặp

Question 5: Consider the following Attendance table which contains an employee attendance record for a company: EmployeeID (int), LongTime(time), LogoutTime(time) Which statement will list all the employee ID that has logged-in most recently.
Bảng Attendance có 3 cột thông tin sau EmployeeID (int), LongTime(time), LogoutTime(time), statement nào sẽ lấy ra tất cả employee ID đăng nhập gần đây nhất.

1. SELECT EmployeeID 
   FROM Attendance 
   GROUP BY LoginTime 
   HAVING MAX(LoginTime)
2. SELECT TOP 1 a.EmployeeID 
   FROM Attendance a
   WHERE EXISTS (SELECT MAX(b.LoginTime) FROM Attendance b GROUP BY EmployeeID HAVING
		 MAX(b.LoginTime) = a.LoginTime AND a.EmployeeID = b.EmployeeID)
3. SELECT TOP 1 a.EmployeeID 
   FROM Attendance a
   WHERE a.LoginTime = (SELECT MAX(b.LoginTime) FROM Attendance b)
4. None of the above.

Answer: Loại A -> HAVING MAX chỉ lấy được 1 employee, B- > Điều kiện HAVING là không cần thiết. Đáp án C (sử dụng một câu sub lấy max LoginTime trong table -> đi tìm Employee có LoginTime = Max Login Time)

Question 6: Which of the following is not a constraint available in SQL?
Ràng buộc nào sau đây không có trong SQL

  1. NOT NULL
  2. UNIQUE
  3. POSITIVE
  4. PRIMARY KEY
  5. CHECK

Answer: Loại đáp án E -> ràng buộc CHECK có mặt ở SQL Server, cho phép thêm điều kiện kiểm tra trên mỗi hàng. Chi tiết tham khảo thêm ở W3Schools

Question 7: Which of the following is not a valid Logical operator?
Cái nào không là toán tử Logical

  1. ABOVE
  2. BETWEEN
  3. IN
  4. NOT

Answer: Đáp án A, SQL không có keyword hay logical operator nào là ABOVE

Question 8: If a column is defined as decimal(5,2), what does that mean?
Nếu cột được khai báo decimal(5,2), nó có nghĩa là?

  1. A number that has 5 digits before the decimal and 2 digits after the decimal.
  2. A number that has 3 digits before the decimal and 2 digits after the decimal.
  3. A number that has 2 digits before the decimal and 3 digits after the decimal.
  4. A number that has 2 digits before the decimal and 5 digits after the decimal.

Answer: Đáp án B, 3 chữ số phía trước phần thập phân và 2 chữ số phía sau. Ex: 521.69

Question 9: How can you get a count of all records in a table?
Làm thế nào lấy count tất cả các records trong table.

  1. SELECT COUNT(*) FROM table_name;
  2. SELECT COUNT FROM table_name;
  3. SELECT SUM(*) FROM table_name;
  4. SELECT COUNT() FROM table_name;

Answer: Đáp án A.

Question 10: Suppose you have the following table with columns:
id name work_date salary
1 john 2016-01024 300
to get an output like ‘1john2016-01-24’ which of the following function can be used?
Nên sử dụng function gì để có kết quả ‘1john2016-01-24’

  1. CONCAT
  2. COMBINE
  3. STRING

Answer: Đáp án A (CONCAT)

Question 11: Which of the following only works with GROUP BY clause?
Cái nào chỉ work với GROUP BY

  1. WHERE
  2. ORDER BY
  3. HAVING
  4. None of above

Answer: HAVING chỉ có thể sử dụng với GROUP BY

Question 12: Which of the following can be used to delete all data from a table?
Cái nào sử dụng để xóa toàn bộ dữ liệu trong bảng?

  1. EMPTY
  2. DROP
  3. TRUNCATE

Answer: Đáp án C (TRUNCATE)

Question 13: For a table with the following data:
Name Marks
John 400
Brown 200
Darwin 350
Kamy 250
Which of the following queries will give you names of all students having above averagemarks?

Câu query nào dưới đây giúp lấy ra tên toàn bộ học sinh có điểm số trên trung bình

1. SELECT name FROM student WHERE marks > (SELECT AVG(marks) FROM student)
2. SELECT name FROM student WHERE marks > AVG(marks)
3. SELECT name FROM student WHERE marks > AVG(marks) DROUP BY marks

Answer: Đáp án A, loại C do DROUP BY, Loại B do AVG(marks) not working.

Question 14: PRIMARY KEY is acombinatin of which two constraints?
PRIMARY KEY bao gồm 2 ràng buộc là?

  1. NOT NULL and UNIQUE
  2. NOT NULL and DISTINCT
  3. UNIQUE and DEFAULT

Answer: Đáp án A, khóa chính chỉ có 2 loại ràng buộc là NOT NULL và UNIQUE.

Question 15: Which of the following are subsets of SQL? (Check any that apply)

  1. DDL
  2. XSL
  3. DSL
  4. DML
  5. XML
  6. XDL

Answer: Đáp án A và D. DDL (Data Definition Language) và DML (Data Manipulation Language)

  • DCL is used to control access to data in a database such as to grant or revokespecified users’ rights to perform specified tasks.
  • DDL is used to define data structures such as to create, alter, or drop tables.
  • DML is used to retrieve and manipulate data in the table such as to insert, delete, and update data. Select, however, becomes a special statement belonging to this subset even though it is a read-only command that will not manipulate data at all.

Question 16: What does MID() function do?

  1. Returns the middle character.
  2. Extract characters from a text field.
  3. Returns the length of a field.

Answer: Đáp án B.

Question 16: Which operator allows you to specify multiple values in a WHERE clause?
Operator nào dưới đây cho phép so sánh nhiều gía trị khi sử dụng với WHERE

  1. LIKE
  2. IN
  3. ==
  4. INSIDE

Answer: Đáp án B. Sử dụng từ khóa IN.

Có gì thắc mắc cứ comment đây nha! - Please feel free to comment here!

Kiên Nguyễn

👋 HEY THERE! 👋. My pleasure when you're here to read the article. Please feel free to comment, send a message or just want to say HELLO. Thank you, from bottom of my heart ❤️❤️❤️. Visit my portfolio: https://kieblog.com

Mời tui ly cà phê

Like page để không bỏ lỡ bài viết mới
Facebook Pagelike Widget
Bài viết mới
Lưu trữ