Transact-SQL is central to using Microsoft SQL Server. Of the world's five most used databases, four use SQL and one of them use T-SQL. The average annual pay for a MS SQL Developer Job in the US is $97'089 a year.
The differences between the two are:
T-SQL adds a number of features that are not available in SQL.
This includes procedural programming elements and a local variable to provide more flexible control of how the application flows. A number of functions were also added to T-SQL to make it more powerful; functions for mathematical operations, string operations, date and time processing, and the like. These additions make T-SQL comply with the Turing completeness test, a test that determines the universality of a computing language. SQL is not Turing complete and is very limited in the scope of what it can do.
Another significant difference between T-SQL and SQL is the changes done to the DELETE and UPDATE commands that are already available in SQL. With T-SQL, the DELETE and UPDATE commands both allow the inclusion of a FROM clause which allows the use of JOINs. This simplifies the filtering of records to easily pick out the entries that match a certain criteria unlike with SQL where it can be a bit more complicated.
IDENTITY column?The limitations of the IDENTITY column is that column values cannot be updated once generated. Also, it may require to specify this column as a PRIMARY KEY, as such, there is a possibility of duplication of values within a table. Identity property is applicable for integer based column only.
OFFSET-FETCH filter in tsql?In TSQL OFFSET-FETCH filter is designed similar to TOP but with an extra element. It helps to define how many rows you want to skip before specifying how many rows you want to filter.
A window function is a function that's applied to a set of rows defined by a window descriptor and returns a single value for each row from the underlying query. The purpose of the window descriptor is to define the set of rows that the function should apply to. You provide the window specification using a clause called OVER.
SELECT empid, ordermonth, qty,
SUM(qty) OVER(PARTITION BY empid
ORDER BY ordermonth
ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW) AS runqty
FROM Sales.EmpOrders;Basically, a primary key is (at the implementation level) a special kind of index. Specifically:
UNIQUE - you cannot have more than one row with the same primary key, since its purpose is to uniquely identify rows.NULL, so the row(s) it consists of must be NOT NULLA table can have multiple indexes, and indexes are not necessarily UNIQUE. Indexes exist for two reasons:
Text, NText and/or Image data type?DATALENGTH command to capture the length.LEN command is invalid for Text, NText and Image data types.If you want to just get number of characters excluding blanks you would use LEN() function, while in all other cases DATALENGTH(). Even LEN() documentation has an information that to get number of bytes to represent the extension you should use DATALENGTH().
Use the SET ROWCOUNT command. So if you had 2 duplicate rows you would issue SET ROWCOUNT 1, then your DELETE command then SET ROWCOUNT 0.
You can let point a synonym to an object of a linked server, but you still need that linked server.
ROLLUP and CUBE in T-SQL?ROLLUP and CUBE are the grouping sets used along with GROUP BY clause to generate summarized aggregations. These are mainly used for Data Audits and Report Generation.
Join Types in TSQL are,
IDENT_CURRENT does?The TSQL command IDENT_CURRENT returns the last identity value produced for a specified table or view. The last identity value created can be for any session and any scope.
When an error occurs in a transaction within a TRY block, and if the error is not serious it enters into a status open and Uncommittable. In an uncommittable state, the transactions cannot perform any action that would generate a write to the transaction log.
This type of join lets you find the data in one table that doesn't exist in another table. It's an alternative to using NOT IN or NOT EXISTS in a WHERE clause like this:
SELECT p.PeopleID, p.Name
FROM dbo.People p
WHERE p.PeopleID NOT IN (SELECT n.PeopleID
FROM dbo.PhoneNumbers n
WHERE n.PeopleID IS NOT NULL); Here's how you can accomplish the same goal using a left outer join with an exclusion:
SELECT p.PeopleID, p.Name
,n.PhoneNumberID, n.PeopleID, n.Number
FROM dbo.People p
LEFT JOIN dbo.PhoneNumbers n
ON p.PeopleID = n.PeopleID
WHERE n.PhoneNumberID IS NULL; COALESCE() and ISNULL(,'')?The ISNULL function and the COALESCE expression have a similar purpose but can behave differently:
Microsoft SQL Server supports different types of XML indexes. An XML index is different than a relational index. There are basically TWO types of XML Indexes:
The Primary XML index is a clustered index on an internal table known as the node table that users cannot use directly from their T-SQL statements. To enhance search performance, we create secondary XML indexes. These create secondary links (RID) at leaf level for existing clustered index based KEY pages. A primary XML index should be created prior to creating the Secondary XML Indexes.
TRUNCATE and DELETE in SQL?The difference between truncate and delete is listed below:
+----------------------------------------+----------------------------------------------+
| Truncate | Delete |
+----------------------------------------+----------------------------------------------+
| We can't Rollback after performing | We can Rollback after delete. |
| Truncate. | |
| | |
| Example: | Example: |
| BEGIN TRAN | BEGIN TRAN |
| TRUNCATE TABLE tranTest | DELETE FROM tranTest |
| SELECT * FROM tranTest | SELECT * FROM tranTest |
| ROLLBACK | ROLLBACK |
| SELECT * FROM tranTest | SELECT * FROM tranTest |
+----------------------------------------+----------------------------------------------+
| Truncate reset identity of table. | Delete does not reset identity of table. |
+----------------------------------------+----------------------------------------------+
| It locks the entire table. | It locks the table row. |
+----------------------------------------+----------------------------------------------+
| Its DDL(Data Definition Language) | Its DML(Data Manipulation Language) |
| command. | command. |
+----------------------------------------+----------------------------------------------+
| We can't use WHERE clause with it. | We can use WHERE to filter data to delete. |
+----------------------------------------+----------------------------------------------+
| Trigger is not fired while truncate. | Trigger is fired. |
+----------------------------------------+----------------------------------------------+
| Syntax : | Syntax : |
| 1) TRUNCATE TABLE table_name | 1) DELETE FROM table_name |
| | 2) DELETE FROM table_name WHERE |
| | example_column_id IN (1,2,3) |
+----------------------------------------+----------------------------------------------+EXEC vs sp_executesql?PARTITION BY and GROUP BYGO in Transact SQL?TRY/CATCH block inside the transaction or should the transaction be inside the TRY block?GUID as a primary key, specifically regarding performance?Rust has been Stack Overflow’s most loved language for four years in a row and emerged as a compelling language choice for both backend and system developers, offering a unique combination of memory safety, performance, concurrency without Data races...
Clean Architecture provides a clear and modular structure for building software systems, separating business rules from implementation details. It promotes maintainability by allowing for easier updates and changes to specific components without affe...
Azure Service Bus is a crucial component for Azure cloud developers as it provides reliable and scalable messaging capabilities. It enables decoupled communication between different components of a distributed system, promoting flexibility and resili...