Font size
WorksheetsMYSQL - FIN
Total questions: 90
Worksheet time: 2hrs 3mins
What is the purpose of the ORDER BY clause in MySQL?
To insert new records
To sort the result set in ascending or descending order
To delete records
To update existing records
Which keyword is used with ORDER BY to sort in descending order?
ASC
DESC
SORT
DOWN
What will happen if you use ORDER BY without specifying ASC or DESC?
It will throw an error
It will sort in ascending order by default
It will sort in descending order by default
It will sort randomly
Which of the following is a valid ORDER BY clause?
ORDER BY column1, column2 DESC
ORDER BY 1, 2
Both a and b
Neither a nor b
The INSERT INTO statement is used to:
Sort data
Add new records to a table
Delete records
Update records
Which syntax is correct for inserting a single row?
INSERT INTO table_name (column1, column2) VALUES (value1, value2)
INSERT table_name VALUES (value1, value2)
Both a and b
Neither a nor b
What happens if you omit column names in an INSERT INTO statement?
NOTE: omitting column names means you don’t specify the columns into which you’re inserting data.
It inserts values into all columns in the order they are defined
It throws an error
It inserts null values
It sorts the data
Which clause can be combined with INSERT INTO to sort the inserted data?
ORDER BY
WHERE
GROUP BY
None of the above
In ORDER BY, what does sorting by a column number (e.g., ORDER BY 2) refer to?
The second row
The second column in the SELECT list
The second table
The second database
Which of the following is a valid INSERT INTO statement?
INSERT INTO users (id, name) VALUES (1, 'John')
INSERT INTO users VALUES (1, 'John')
Both a and b
Neither a nor b
What is the default sort order for ORDER BY when using a text column?
Ascending
Descending
Random
Alphabetical only
How many rows can be inserted using a single INSERT INTO statement?
1
Multiple
0
Depends on the database
Which of the following ORDER BY clauses will sort by the "age" column in descending order?
ORDER BY age ASC
ORDER BY age DESC
ORDER BY age UP
ORDER BY age DOWN
What is required when using INSERT INTO with specified columns?
Values for all columns
Values for specified columns only
No values
Sorted values
Which of the following is true about ORDER BY?
It modifies the table data
It only affects the display order
It deletes rows
It inserts new rows
What happens if you try to insert a duplicate primary key with INSERT INTO?
It inserts the row
It throws an error
It updates the existing row
It sorts the data
Which ORDER BY syntax is invalid?
ORDER BY column_name
ORDER BY 1
ORDER BY column_name, 2 DESC
ORDER BY NULL
How can you insert data into specific columns only?
Omit the column names
Specify column names and provide values
Use ORDER BY
Use DELETE
What is the effect of ORDER BY on a query with no results?
It throws an error
It returns an empty sorted result
It inserts data
It updates data
Which INSERT INTO syntax allows multiple rows?
INSERT INTO table_name (col1, col2) VALUES (val1, val2), (val3, val4)
INSERT INTO table_name VALUES (val1, val2)
Both a and b
Neither a nor b
What is the purpose of specifying column names in INSERT INTO?
To sort the data
To define which columns receive values
To delete columns
To update columns
Which ORDER BY clause sorts by multiple columns?
ORDER BY col1, col2
ORDER BY col1 + col2
ORDER BY (col1, col2)
ORDER BY col1 OR col2
What happens if a value in INSERT INTO exceeds the column's data type limit?
It truncates the value
It throws an error
It sorts the data
It inserts null
Which ORDER BY option is case-sensitive by default?
Yes
No
Depends on collation
Never
What is the minimum requirement for an INSERT INTO statement?
Table name and values
Column names only
ORDER BY clause
WHERE clause
Debug this query: SELECT * FROM students ORDER BY age DESC; (Assume table has columns: id, name)
Debug this query: INSERT INTO users (id, name) VALUES ('1', 'John'); (id is INT)
Debug this query: SELECT * FROM employees ORDER BY salary UP;
Debug this query: INSERT INTO customers VALUES ('1', 'Alice'); (id INT, name VARCHAR)
Debug this query: INSERT INTO products (id, price) VALUES (1, '100.50'); (price is DECIMAL)
Debug this query: SELECT * FROM staff ORDER BY name, dept; (dept not in SELECT)
Debug this query: INSERT INTO employees (id) VALUES ();
Debug this query: SELECT * FROM users ORDER BY email DESC, name ASC; (email not in table)
Debug this query: INSERT INTO teachers (id, name) VALUES (1, ), (2, 'Bob');
Debug this query: SELECT * FROM students ORDER BY grade, age DESC; (grade not in table)
Debug this query: INSERT INTO clients (id, name) VALUES (1, NULL); (name is NOT NULL)
Debug this query: SELECT * FROM orders ORDER BY total PRICE;
Debug this query: INSERT INTO products (id, name) VALUES (1), (2);
Debug this query: INSERT INTO users (id, name) VALUES (1, 'John', 'extra');
Debug this query: INSERT INTO staff (id) VALUES (1, 'Jane');
Debug this query: INSERT INTO students (id, name) VALUES ((1), 'Alice');
The ORDER BY clause permanently changes the data in a table.
True
False
You can use ORDER BY with multiple columns in a single query.
True
False
The INSERT INTO statement requires column names to be specified.
True
False
ORDER BY can sort data in ascending order only.
True
False
INSERT INTO can add multiple rows in one statement.
True
False
The default sort order for ORDER BY is descending.
True
False
INSERT INTO will fail if a value violates a primary key constraint.
True
False
ORDER BY affects the underlying table structure.
True
False
You can insert NULL values into a column with INSERT INTO if the column allows NULL.
True
False
The ORDER BY clause must be used with a SELECT statement.
True
False
INSERT INTO can update existing rows.
True
False
You can sort by a column not included in the SELECT list with ORDER BY.
True
False
The INSERT INTO statement requires all columns to have values.
True
False
ORDER BY can sort numeric and text data.
True
False
The DESC keyword reverses the default sort order.
True
False
INSERT INTO can insert data into a view.
True
False
The ORDER BY clause is case-sensitive by default.
True
False
The clause used to sort the result set is _____ __.
(a)
To insert a new record, use the ______ ____ statement.
(a)
The keyword (a) sorts data in descending order.
The default sort order for ORDER BY is (a) .
To insert multiple rows, use ______ ____ with multiple VALUE sets.
(a)
The keyword (a) is used to specify values in an INSERT INTO statement.
ORDER BY can sort by the (a) position in the SELECT list.
An error occurs in INSERT INTO if a (a) key constraint is violated.
What will be the output of: SELECT name FROM students ORDER BY age DESC; (age: 20, 15, 25; names: Alice, Bob, Charlie)
(a)
What will be the output of: SELECT id, name FROM users ORDER BY id; (id: 3, 1, 2; names: Carol, Alice, Bob)
(a)
What will be the output of: SELECT * FROM employees ORDER BY salary DESC; (salary: 5000, 3000, 4000)
(a)
What will be the output of: INSERT INTO students (id, name) VALUES (1, 'John');
SELECT * FROM students;
(a)
What will be the output of: SELECT name FROM teachers ORDER BY name DESC; (names: David, Anna, Bob)
(a)
What will be the output of: SELECT * FROM products ORDER BY price; (price: 10.5, 5.0, 15.0)
(a)
What will be the output of: INSERT INTO users (id, name) VALUES (1, 'Alice'), (2, 'Bob');
SELECT * FROM users; (empty table)
(a)
What will be the output of: SELECT name FROM customers ORDER BY 1; (names: Eve, Adam, Charlie)
(a)
What will be the output of: INSERT INTO employees (id, name) VALUES (1, 'John'); SELECT name FROM employees;
(a)
To retrieve all the records from the "users" table, use: SELECT (a) FROM users;
To update the name column in the users table where id = 1:
UPDATE users SET name = 'John' WHERE (a) = 1;
Given table students(name, age) with one row: ('Anna', 20). What is the output? SELECT age FROM students WHERE name = 'Anna';
(a)
What is the error in: INSERT INTO products (id) VALUES ('a'); (id is INT)
What is the error in: SELECT * FROM students ORDER BY;
What is the error in: INSERT INTO teachers VALUES (1); (id, name columns)
What is the error in: INSERT INTO clients (id, name) VALUES (1, 1); (name is VARCHAR)
What is the error in: SELECT * FROM orders ORDER BY 0;
What is the error in: INSERT INTO students (id, name) VALUES (1, NULL); (name NOT NULL)
What is the issue with: INSERT INTO courses (course_id, course_name) VALUES (101, NULL); (course_name NOT NULL)
What will be the output of: SELECT name FROM customers ORDER BY age DESC; (age: 30, 30, 25; names: Alice, Bob, Charlie)
(a)
What will be the output of: INSERT INTO products (id) VALUES (1); SELECT * FROM products; (id INT, name VARCHAR DEFAULT 'Unknown')
What is the error in: SELECT * FROM users ORDER BY (email + name); (email VARCHAR, name VARCHAR)
What is the error in: INSERT INTO employees (id, salary) VALUES (1, 'invalid'); (salary DECIMAL)
What is the issue with: INSERT INTO employees (id, salary) VALUES (2, 'text'); (salary DECIMAL)
