Self Studies

Computer Science Test - 6

Result Self Studies

Computer Science Test - 6
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    5 / -1
    Which of the following is a correct syntax to create a table inside database?
    Solution

    The correct answer is Option 4.

     

    Key Points

    The CREATE TABLE statement is used to create a new table in a database.

     

    Create table Syntax: 

    CREATE TABLE tablename(

    attributename1 datatype constraint,

    attributename2 datatype constraint,

    :

    attributenameN datatype constraint

    PRIMARY KEY( one or more columns )

    );

     

    Example of a Student Table:

     

    CREATE TABLE Student (

        StudentID int,

        LastName varchar(255),

        FirstName varchar(255),

        Class int,

        City varchar(255)

        PRIMARY KEY (StudentID)

    );

     

    The attributename parameters specify the names of the columns of the table.

    The datatype parameter specifies the type of data the column can hold (e.g. integer, date, varchar, etc.).

     

    Considering

    option 1: CREATE DATABASE tablename(......) //here it violates the syntax for creating table//

    option 2: CREATE ___ tablename(......) //here it misses the keyword TABLE//

    option 3: CREATE TABLE tablename( datatype attributename1  constraint, ........................) //here it violates the syntax by assigning datatype first before attribute name//

  • Question 2
    5 / -1

    Which of the following keyword is used to eliminate duplicate records in SQL?

    Solution

    The SELECT DISTINCT statement is used to return only distinct (different) values.

    Syntax

    SELECT DISTINCT column1, column2, ... FROM table_name;

    For example

    There is a table name Student_details having few attributes

    Student Name

    Department

    City

    A

    CSE

    Haridwar

    B

    CE

    Haridwar

    C

    ME

    Dehradun

    D

    CSE

    Rishikesh

    E

    IT

    Rishikesh

    Without DISTINCT

    The following statement returns all cities of all Students in the Student_details tables:

    SELECT city FROM Student_details;

    City

    Haridwar

    Haridwar

    Dehradun

    Rishikesh

    Rishikesh

    As you can see clearly from the output, the cities are duplicate.

    With DISTINCT

    SELECT DISTINCT city FROM Student_details

    City

    Haridwar

    Dehradun

    Rishikesh

  • Question 3
    5 / -1
    The names of the tables that an user can have access to or that he or she has created, can be displayed with the following SQL query:
    Solution

    Query Syntax for listing the tables in SQL

    • Show all tables owned by the current user

    SELECT  table_name FROM  user_tables;

    • Show all tables in the current database

    SELECT  table_name FROM  dba_tables;

    • Show all tables that are accessible by the current user

    SELECT  table_name FROM  all_tables;

    Therefore, Correct answer is Option 1

  • Question 4
    5 / -1
    Which of the following is not a transaction management SQL command ? 
    Solution

    Concept:

    A transaction can be defined as a unit of part of any program at the time of its execution. During this, data items can be read or updated or both. Transaction management is the ability of database management system to manage the different transactions that occur within it.

    Explanation:

    Concurrency control is the activity of coordinating the actions of transactions that operate simultaneously to access the shared data. Transaction control language commands are used to manage the transaction in the database. These commands are:

    COMMIT:

    It is used to permanently save any transaction in the database. When changes are done in the transaction , then those changes are not permanent until we perform the COMMIT operation on that.

    ROLLBACK:

    This command restores the database to the last committed state. If sometimes after changing the data, we realize that changes are not required, then ROLLBACK command is applied at that point.

    SAVEPOINT:

    This is used to temporarily save a transaction so that rollback can be performed whenever required. Syntax for this is : SAVEPOINT savepoint_name;

  • Question 5
    5 / -1
    When using the SQL INSERT statement :
    Solution

    The correct answer is option 4.

    Concept:

    The INSERT INTO statement is used to insert new records in a table and the rows can either be inserted into a table one at a time or in groups. The SQL Insert command is possible to write the INSERT INTO statement in two ways:

    Specify both the column names and the values to be inserted in the group of attributes in the table.

    Syntax:

    INSERT INTO table_name (column1, column2, column3, ...)

    VALUES (value1, value2, value3, ...);

    The column names do not need to be specified in the SQL query if we are adding values to all of the table's columns. Make sure the values are in the same order as the table columns and the rows inserted into a table one at a time

    Syntax:

    INSERT INTO table_name

    VALUES (value1, value2, value3, ...);

    Hence the correct answer is rows can either be inserted into a table one at a time or in groups.

  • Question 6
    5 / -1
    Which of the following is used for single-line comment in SQL?
    Solution

    Concept:

    Comments can make your application easier for you to read and maintain. For example, you can include a comment in a statement that describes the purpose of the statement within your application. With the exception of hints, comments within SQL statements do not affect the statement execution.

    A comment can appear between any keywords, parameters, or punctuation marks in a statement. You can include a comment in a statement in two ways:

    • Begin the comment with a slash and an asterisk (/*). Proceed with the text of the comment. This text can span multiple lines. End the comment with an asterisk and a slash (*/). The opening and terminating characters need not be separated from the text by a space or a line break.

    • Begin the comment with -- (two hyphens). Proceed with the text of the comment. This text cannot extend to a new line. End the comment with a line break.

  • Question 7
    5 / -1
    The SQL ALTER TABLE statement is used to:
    Solution

    Concept:

    The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.

    The ALTER TABLE statement is also used to add and drop various constraints on an existing table.

    ADD Column

    To add a column in a table, use the following syntax:

    ALTER TABLE table_name ADD column_name datatype;

    DROP COLUMN

    To delete a column in a table, use the following syntax (notice that some database systems don't allow deleting a column):

    ALTER TABLE table_name DROP COLUMN column_name;

  • Question 8
    5 / -1
    Which one of the following is used to sort rows in SQL?
    Solution

    Concept:

    The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".

    The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

    GROUP BY Syntax

    SELECT column_name(s)
    FROM table_name
    WHERE condition
    GROUP BY column_name(s)
    ORDER BY column_name(s);

    The ORDER BY keyword is used to sort the result-set in ascending or descending order.

    The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

    ORDER BY Syntax

    SELECT column1, column2, ...
    FROM table_name
    ORDER BY column1, column2, ... ASC|DESC;

  • Question 9
    5 / -1

    The _________ clause is an additional filter that is applied to the result set in a SQL statement.

    Solution

    Concept:

    The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".

    The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.

    GROUP BY Syntax

    SELECT column_name(s)
    FROM table_name
    WHERE condition
    GROUP BY column_name(s)
    ORDER BY column_name(s);

    The ORDER BY keyword is used to sort the result-set in ascending or descending order.

    The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

    ORDER BY Syntax

    SELECT column1, column2, ...
    FROM table_name
    ORDER BY column1, column2, ... ASC|DESC;

    The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

    HAVING Syntax

    SELECT column_name(s)
    FROM table_name
    WHERE condition
    GROUP BY column_name(s)
    HAVING condition
    ORDER BY column_name(s);

    The SELECT statement is used to select data from a database.

    The data returned is stored in a result table, called the result-set. 

    SELECT Syntax

    SELECT column1, column2, ...
    FROM table_name;

    Hence Option C is correct

  • Question 10
    5 / -1
    In SQL – the function - avg, min, max, sum, count are called as _______.
    Solution
    • In SQL, the function - avg, min, max, sum, count is called as aggregate function.
    • Aggregate functions return a single value after calculating from a group of values.
    • avg() function returns the average values, max() returns the maximum value, count() finds the number of rows that matches the specified condition, min() returns the minimum value, Max() returns the maximum value. sum() returns the sum of values.


    Example:

    SELECT AVG(salary

    FROM employees

    GROUP BY department_id;

Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now