SQL Server Basics Quiz
15 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What does the query SELECT DATEDIFF(day, '2023-01-01', '2023-01-15'); return?

  • 14 (correct)
  • 15
  • 16
  • 13
  • What is a primary advantage of using the IDENTITY property in SQL Server?

  • It automatically generates a unique number for a new row (correct)
  • It is used to create a default value for columns
  • It enforces uniqueness across multiple columns
  • It allows indexing on a composite key
  • Which statement is true about a clustered index in SQL Server?

  • It can only be created on primary key columns
  • It allows multiple clustered indexes per table
  • It modifies the physical storage of the data rows in the table (correct)
  • It requires all columns in the index to be unique
  • What output does the query SELECT REPLICATE('SQL', 3); provide?

    <p>'SQLSQLSQL'</p> Signup and view all the answers

    In SQL Server, the WITH keyword used in a query is primarily utilized for what purpose?

    <p>It creates a Common Table Expression (CTE)</p> Signup and view all the answers

    Which function is used in SQL Server to handle NULL values effectively?

    <p>COALESCE</p> Signup and view all the answers

    What role does the CASE statement serve in SQL Server?

    <p>It allows conditional logic within a query</p> Signup and view all the answers

    What occurs if a DELETE query lacks a WHERE clause in SQL Server?

    <p>All records in the table are deleted</p> Signup and view all the answers

    What does the SQL query return when using 'SELECT TOP(5) * FROM Orders ORDER BY OrderDate DESC'?

    <p>The 5 most recent orders based on OrderDate</p> Signup and view all the answers

    Which statement accurately reflects the behavior of transactions in SQL Server?

    <p>A transaction is automatically committed if no errors occur</p> Signup and view all the answers

    What does the UNION operator accomplish in SQL Server?

    <p>It returns all distinct rows from two or more result sets</p> Signup and view all the answers

    How can one force the SQL Server query optimizer to use a specific index?

    <p>By using the <code>INDEX</code> hint in the query</p> Signup and view all the answers

    What is the result of executing 'SELECT DISTINCT Name FROM Customers'?

    <p>Returns unique customer names</p> Signup and view all the answers

    Which characteristic is true regarding table variables in SQL Server?

    <p>Table variables are stored in memory and are faster than temporary tables</p> Signup and view all the answers

    What is the primary function of the ROW_NUMBER() function in SQL Server?

    <p>It assigns a unique number to each row, starting from 1</p> Signup and view all the answers

    Study Notes

    SQL Server Query Insights

    • DATEDIFF function: Returns the difference in days between two dates. In the given example, it calculates the days from '2023-01-01' to '2023-01-15', resulting in 14 days.
    • IDENTITY property: Automatically generates a unique integer for new rows in a table, often used for primary keys.
    • Clustered Index: Organizes data rows in a table in sorted order based on the indexed column(s) and improves retrieval performance. It can be created on any column, not just primary keys.

    SQL Server String Functions

    • REPLICATE function: Duplicates a given string for a specified number of times. Using REPLICATE('SQL', 3) results in 'SQLSQLSQL'.
    • Common Table Expression (CTE): Defined using the WITH keyword, allowing for temporary result sets within a main query.

    SQL Server Functions and Conditional Logic

    • COALESCE function: Returns the first non-NULL value from a list of expressions, useful for handling NULL values.
    • CASE statement: Enables conditional logic within SQL queries; it can evaluate multiple conditions and return specific results based on those evaluations.

    SQL Server Data Manipulation

    • DELETE statement without WHERE clause: If executed without a WHERE clause, it will delete all records from the specified table.
    • FILESTREAM storage: Allows storage of unstructured data, such as text files, directly in SQL Server.

    SQL Server Query Syntax

    • TOP clause: Retrieves a specified number of records; SELECT TOP(5) * FROM Orders ORDER BY OrderDate DESC returns the 5 most recent orders based on the OrderDate.
    • Transactions in SQL Server: Automatically committed if no errors occur, ensuring data integrity. They can be nested and are compatible with DELETE operations.

    SQL Server Set Operations

    • UNION operator: Combines two or more result sets and returns only distinct rows from them.
    • INDEX hint: Forces the query optimizer to utilize a specified index, which can impact performance.

    SQL Server Data Retrieval

    • DISTINCT keyword: Used in queries to return only unique records from a result set, as demonstrated by SELECT DISTINCT Name FROM Customers returning only unique customer names.

    SQL Server Table Variables

    • Table variables: Stored in memory and typically offer better performance for small data sets compared to temporary tables. They support basic transactions and are limited regarding indexing capabilities.

    Window Functions

    • ROW_NUMBER() function: Assigns a sequential integer to rows within a result set, starting from 1, often used for pagination or ranking.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    SQL_medium_questions.pdf

    Description

    Test your knowledge on SQL Server fundamentals with this quiz. You will encounter questions related to date functions, the IDENTITY property, and other essential SQL concepts. Perfect for beginners looking to strengthen their skills!

    More Like This

    Use Quizgecko on...
    Browser
    Browser