Browsed by
Author: priya

What is a View

What is a View

View is a virtual table which is created on the basis of the result set returned by the select statement. CREATE VIEW [MyView] AS SELECT * from pcdsEmployee where LastName = ‘singh’ In order to query the view SELECT * FROM [MyView] A view in a database management system (DBMS) is a virtual table that is based on the result of a SELECT query. It presents data from one or more tables in the database in a structured format, similar…

Read More Read More

Can you explain the SELECT INTO Statement

Can you explain the SELECT INTO Statement

SELECT INTO statement is used mostly to create backups. The below SQL backsup the Employee table in to the EmployeeBackUp table. One point to be noted is that the structure of pcdsEmployeeBackup and pcdsEmployee table should be same. SELECT * INTO pcdsEmployeeBackup FROM pcdsEmployee. Certainly! The SELECT INTO statement in a database management system (DBMS) is used to create a new table based on the result set returned by a SELECT query. Here’s how it works: SELECT Query: First, you…

Read More Read More

What are Aggregate and Scalar Functions

What are Aggregate and Scalar Functions

Aggregate and Scalar functions are in built function for counting and calculations. Aggregate functions operate against a group of values but returns only one value. AVG(column) :- Returns the average value of a column COUNT(column) :- Returns the number of rows (without a NULL value) of a column COUNT(*) :- Returns the number of selected rows MAX(column) :- Returns the highest value of a column MIN(column) :- Returns the lowest value of a column Scalar functions operate against a single…

Read More Read More

What is a Sub-Query

What is a Sub-Query

A query nested inside a SELECT statement is known as a subquery and is an alternative to complex join statements. A subquery combines data from multiple tables and returns results that are inserted into the WHERE condition of the main query. A subquery is always enclosed within parentheses and returns a column. A subquery can also be referred to as an inner query and the main query as an outer query. JOIN gives better performance than a subquery when you…

Read More Read More

What is “Group by” clause

What is “Group by” clause

Group by” clause group similar data so that aggregate values can be derived. The “Group by” clause in a database management system (DBMS) is used to group rows that have the same values into summary rows or groups based on one or more columns. It is commonly used with aggregate functions like COUNT, SUM, AVG, MAX, or MIN to perform calculations on each group of rows. Essentially, it helps in categorizing data and applying aggregate functions to each category.

What are cursors and what are the situations you will use them

What are cursors and what are the situations you will use them

SQL statements are good for set at a time operation. So it is good at handling set of data. But there are scenarios where we want to update row depending on certain criteria. we will loop through all rows and update data accordingly. There’s where cursors come in to picture. Cursors in database management systems (DBMS) are programming constructs used to retrieve and manipulate data from a result set, typically within a procedural language like SQL or PL/SQL. They enable…

Read More Read More

What’s the difference between “UNION” and “UNION ALL

What’s the difference between “UNION” and “UNION ALL

UNION SQL syntax is used to select information from two tables. But it selects only distinct records from both the table. , while UNION ALL selects all records from both the tables. The main difference between “UNION” and “UNION ALL” in database management systems (DBMS) lies in how they handle duplicate rows. UNION: This operator combines the result sets of two or more SELECT statements, removing any duplicate rows from the final result set. It effectively performs a set union…

Read More Read More

What’s the difference between DELETE and TRUNCATE

What’s the difference between DELETE and TRUNCATE

Following are difference between them: DELETE TABLE syntax logs the deletes thus making the delete operations low. TRUNCATE table does not log any information but it logs information about deallocation of data page of the table. So TRUNCATE table is faster as compared to delete table. DELETE table can have criteria while TRUNCATE can not. TRUNCATE table can not have triggers.

What is a self-join

What is a self-join

If we want to join two instances of the same table we can use self-join. A self-join in a database management system (DBMS) is when a table is joined with itself. This can be useful when you want to compare rows within the same table. For example, in a table representing employees, you might use a self-join to find pairs of employees who share the same manager.

How to select the first record in a given set of rows

How to select the first record in a given set of rows

Select top 1 * from sales.salesperson To select the first record in a given set of rows in a database management system (DBMS), you can typically use the LIMIT clause in conjunction with the ORDER BY clause to specify the ordering of the rows. The LIMIT clause restricts the number of rows returned by the query, and by combining it with ORDER BY, you can ensure that the first row returned is the one you want. Here’s an example in…

Read More Read More