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
  1. Select * from tables

  2. Select * from tab

  3. Select * from tabs

  4. Select all from tab

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

The above statement is a valid statement and will display a list of tables available in a user's account. The statement will also print the names of the available view, synonyms etc. The select * from tab statement actually queries a synonym named tab which is in the System user account. All the users created in Oracle have a default access to the synonym. Therefore when we are issuing the above statement we are in fact querying the said synonym.

Multiple choice
  1. Undo

  2. Recover

  3. Rollback

  4. Recall

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

Rollback is a part of Transaction Control Language or (TCL). It is used to cancel or undo any changes made in a table. For example, it the user has accidently deleted the data, it can be easily rollbacked to the previous state. The other commands of the same category (TCL) are commit, savepoint etc.

Multiple choice
  1. view

  2. object

  3. synonym

  4. alias

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

Alias is the temporary name given to a table or a column. An alias is quite useful where the name of the table is lengthy and the name has to be written more than once in a statement. A table alias is generally a word with one or two letters that can substitute a table name. For example, if the name of a table is sales_1999, then instead of writing sales_1999 everytime it is required, we can create an alias an use it. Consider the following statement: Select s.data from sales_1999 where s.no=101 in the above statement. S is an alias and it is used as a substitution for the word sales_1999.

Multiple choice
  1. deletes all the records from a table

  2. deletes all the rows along with the table

  3. deletes the structure of the table leaving rows intact

  4. deletes only the null rows of a table

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

The Truncate Table statement is used to delete all the rows of a table at once. The statement allows the user to delete all the records without specifying a condition using the where clause. Truncate  deletes all the records but keeps the structure of the table intact. The output of this statement is equivalent to the delete statement without the where statement.

Multiple choice
  1. when the data type of the column is varchar

  2. when the column is empty

  3. Anytime we want, there are no restrictions

  4. If we are logged in as SYSTEM

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

To modify a column that already has data in it, it is compulsory to first empty the whole column. When all the values of the column are emptied we can modify the datatype of the column. To empty a column, we can use the following SQL statement.Update tablename set columnname=nullFor example, to empty all the values of the column address of the table customer the statement will beupdate customer set address = nullTo modify the datatype of the column we can use the following SQL Statementalter table customer modify(address varchar(10))  

Multiple choice
  1. affect no record

  2. affect all the records

  3. return an error

  4. affect only the first record

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

The where clause is an optional statement in a Select/Delete/Update statement. If it is omitted then the command will affect all the records of the table. For example,  the statement delete from employees will delete all the records in the table.

Multiple choice
  1. colon (:)

  2. period (.)

  3. comma (,)

  4. space

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

Comma is the valid separator in an in clause. The in keyword is used with where to provide a list of values to select. For example, to select all those records where the value in column sport is either Cricket or Football, the statement will select * from players where sport in ('Cricket','Football') The above statement will separate all the rows where the value of the column sport is Cricket or Football.

Multiple choice
  1. Save All

  2. Save Now

  3. Commit

  4. Commits

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

To save changes made to a table, the Commit statement can be issued. Commit is a part of TCL or Transaction Control Language. TCL statements are those statements that are used to save or cancel the changes made to a table. Commit is used for saving the changes whereas the rollback statement is used to cancel the changes. Oracle also provides the user to commit the changes automatically by typing the statement Set autocommit on.

Multiple choice
  1. &&

  2. and

  3. &

  4. *

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

In SQL to combine 2 or more condition in a statement, we can use the logical operators like - and & or. The or operator joins 2 or more conditions are return those records that satisfy any of the given conditions. The and operator is used to display those records that satisfy all the given conditions. For example to see the records of a table named students that have a percentage between 50 and 60 the following SQL can be usedselect * from students where percentage>50 and percentage<60.< em=""> 60.<>

Multiple choice
  1. Select [all] from company list where company = IBM

  2. Select * from company list where company = IBM

  3. Select * from company list where company = ibm

  4. Select * * from company list where company = IBM

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

The where clause is used to limit the effect of a select/delete/update to only those records that meet the given condition. The above statement will display all those records where company is IBM. Although SQL is a case insensitive language, special care must be taken while comparing a text value with another since it matches the text and the case also.

Multiple choice
  1. select * from books order by author

  2. select * from books by order desc

  3. select * from books order by author desc

  4. select * from books sort by author desc

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

The Order By statement is used to display the records in a particular order. For example, the statement select * from students order by address will print all the records alphabetically on the basis of address. By adding a desc clause we can sort the records in descending order. The statement select * from players order by match desc and will print all the records from the players table in descending order of the match column.

Multiple choice
  1. Select column(*) from sample

  2. Select count() from sample

  3. Select column() from sample

  4. Select count(*) from sample

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

Count is an aggregate or group function. It is used to count the number of records in a table or number of not null values in a column. It can be used in the following ways:1. Select count(*) from tablename, the above statement will display the number of records in a table.2. Select count(address) from tablename, the above statement will display the number of values in the address column. It will not count the rows where the column address has a NULL value.Some other aggregate functions are1. Sum, 2. Min, 3. Max, 4. Avg etc.

Multiple choice
  1. SELECT * FROM city WHERE cityname = '%A%'

  2. SELECT * FROM city WHERE cityname = 'A'

  3. SELECT * FROM city WHERE cityname LIKE '%A'

  4. SELECT * FROM city WHERE cityname LIKE 'A%'

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

The above statement will print all those records where the city name starts with 'A'. The wildcard character '%' is used to substitute a whole string. Therefore all those city names will be printed that begins with 'A'. For example, 'Ahemdabad', 'Akola' etc.

Multiple choice
  1. Create table target (Select * from source)

  2. Create table target from source

  3. Create table target from source as select * from source

  4. Create table target as select * from source

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

To create a copy of an existing table we can use a select statement. The target table in this case will be automatically created. The select statement can be any valid select statement and can also include a where clause. The statement will create a table named target having the same data and structure of the source table. For example, if we want to create a copy of table A with the name B, but we we want to copy only those records where the value of mark column is more than 50. We can use the following statement Create table B as select * from A where marks>50 .

Multiple choice
  1. Update table papers set name=null

  2. Update papers set name=null

  3. Update papers set name is null

  4. Update name set papers=null

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

The above statement will set the name column to null or empty values. The null keyword is used both with the = operator and is operator. When a statement like select/delete/update is used with a where clause, null is used with is for example select * from papers where name is null.But while accessing records with a null value, the = operator is used for example delete from papers where names is null.