Computer Knowledge

Database and SQL

3,929 Questions

Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.

SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions

Database and SQL Questions

Multiple choice technology programming languages
  1. To retrieve data.

  2. To insert data.

  3. To modify data.

  4. All the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The INSERT command in SQL is specifically designed to add new rows of data into a table. It is not used for retrieving (SELECT) or modifying (UPDATE) existing data - those are separate SQL commands.

Multiple choice technology programming languages
  1. checks if the table has primary key specified

  2. deletes the table

  3. deletes all rows from a table

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The TRUNCATE TABLE command is a DDL operation that removes all rows from a table. It is faster than DELETE because it deallocates the data pages instead of logging individual row deletions, but it keeps the table structure intact.

Multiple choice technology databases
  1. 123

  2. 12

  3. 123456

  4. 456

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In T-SQL, SUBSTRING(string, start, length) uses 1-based indexing. However, if start is 0, it starts 'before' the first character. For SUBSTRING('123456', 0, 3), it takes the character at index 0 (nothing), index 1 ('1'), and index 2 ('2'), resulting in '12'.

Multiple choice technology databases
  1. 09/09/2008

  2. 09-09-2008 00:00:00:000

  3. Error Message

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The DATE data type was introduced in SQL Server 2008. In SQL Server 2005 and earlier versions, attempting to use 'declare @d date' will result in an error because the DATE type doesn't exist in those versions. The code will fail at the declaration stage itself, never reaching the assignment statement. This is a common compatibility issue when migrating code between SQL Server versions.

Multiple choice technology databases
  1. 8000

  2. 4000

  3. 4005

  4. 5

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The unicode prefix N'hello' makes the string a unicode string (nvarchar), while replicate('-', 8000) produces a regular varchar string. When concatenating unicode and non-unicode strings, SQL Server implicitly converts to unicode (nvarchar), but the variable @c is declared as varchar(8000), not nvarchar. The implicit conversion truncates to 4000 characters because unicode strings require 2 bytes per character. Therefore, len(@c) returns 4000, not 8000.

Multiple choice technology databases
  1. 123

  2. 12

  3. 123456

  4. 456

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

SQL Server's SUBSTRING function uses 1-based indexing, not 0-based. When you call SUBSTRING('123456', 0, 3), it starts from position 0, which is treated as position 1. It then returns 3 characters starting from that position, giving you '12'. This is different from many programming languages that use 0-based indexing and is a common source of confusion for developers new to SQL Server.

Multiple choice technology databases
  1. Primary key access

  2. Full table scan

  3. Access via unique index

  4. Table access by ROWID

  5. None of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Primary key access is generally the fastest method for Oracle to retrieve a single row because primary keys are unique and have mandatory indexes. When you query by primary key, Oracle can use the index to quickly locate the exact row. Access by ROWID is equally fast when you already have the ROWID, but primary key is typically the standard fastest method. Full table scans are slow for single row retrieval, and unique index access is similar but secondary to primary key access in most scenarios.

Multiple choice technology programming languages
  1. SELECT, CONNECT, RESOURCE

  2. SELECT,INSERT,DELETE

  3. INSERT,DELETE,MODIFY,

  4. None Of The Above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Oracle, SELECT, INSERT, and DELETE are object privileges, while CONNECT and RESOURCE are legacy roles (collections of system privileges). While the question asks for 'privileges', the first option represents the standard administrative roles often granted to new users to allow them to connect and create objects.

Multiple choice technology programming languages
  1. DISTINCT

  2. UNIQUE

  3. DISTINCT and UNIQUE

  4. None Of The Above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The DISTINCT keyword is used in a SELECT statement to remove duplicate rows from the result set, ensuring each row is unique. While UNIQUE is a constraint used during table creation to prevent duplicate entries in a column, it is not a valid SQL command for filtering query results.