Interview Quizz Logo

 
  • Home
  • About Us
  • Electronics
  • Computer Science
  • Physics
  • History
  • Contact Us
  • ☰
  1. Computer Science
  2. Programming Technologies
  3. Transact-SQL (T-SQL) Interview Question with Answer

Transact-SQL (T-SQL) Questions and Answers for Viva

Frequently asked questions and answers of Transact-SQL (T-SQL) in Programming Technologies of Computer Science to enhance your skills, knowledge on the selected topic. We have compiled the best Transact-SQL (T-SQL) Interview question and answer, trivia quiz, mcq questions, viva question, quizzes to prepare. Download Transact-SQL (T-SQL) FAQs in PDF form online for academic course, jobs preparations and for certification exams .

Intervew Quizz is an online portal with frequently asked interview, viva and trivia questions and answers on various subjects, topics of kids, school, engineering students, medical aspirants, business management academics and software professionals.




Interview Question and Answer of Transact-SQL (T-SQL)


Question-1. What is T-SQL?

Answer-1: T-SQL (Transact-SQL) is an extension of SQL used in Microsoft SQL Server for procedural programming, error handling, and transaction control.



Question-2. How is T-SQL different from standard SQL?

Answer-2: T-SQL includes control-of-flow, error handling, variables, stored procedures, functions, and transactions, which are not present in standard SQL.



Question-3. What is the difference between CHAR and VARCHAR in T-SQL?

Answer-3: CHAR has a fixed length, while VARCHAR has a variable length and saves space.



Question-4. How do you declare a variable in T-SQL?

Answer-4: DECLARE @variableName INT;



Question-5. How do you assign a value to a variable in T-SQL?

Answer-5: SET @variableName = 100; or SELECT @variableName = column FROM Table;



Question-6. What is a stored procedure in T-SQL?

Answer-6: A precompiled set of SQL statements that can be executed multiple times.



Question-7. How do you create a stored procedure in T-SQL?

Answer-7: CREATE PROCEDURE ProcName AS BEGIN SELECT * FROM Table END;



Question-8. What is the difference between DELETE and TRUNCATE?

Answer-8: DELETE removes rows one by one and logs them, while TRUNCATE removes all rows instantly without logging.



Question-9. What is a trigger in T-SQL?

Answer-9: A special procedure that automatically executes in response to an INSERT, UPDATE, or DELETE event on a table.



Question-10. How do you create a trigger in T-SQL?

Answer-10: CREATE TRIGGER trgName ON Table AFTER INSERT AS BEGIN PRINT 'Insert Trigger Fired' END;



Question-11. What are transactions in T-SQL?

Answer-11: A sequence of operations that are executed as a single unit (Atomicity, Consistency, Isolation, Durability - ACID).



Question-12. How do you start a transaction in T-SQL?

Answer-12: BEGIN TRANSACTION;



Question-13. How do you commit a transaction in T-SQL?

Answer-13: COMMIT TRANSACTION;



Question-14. How do you roll back a transaction in T-SQL?

Answer-14: ROLLBACK TRANSACTION;



Question-15. What is the difference between INNER JOIN and OUTER JOIN?

Answer-15: INNER JOIN returns only matching records, while OUTER JOIN returns all records with NULLs for non-matching rows.



Question-16. How do you use LEFT JOIN in T-SQL?

Answer-16: SELECT * FROM TableA LEFT JOIN TableB ON TableA.ID = TableB.ID;



Question-17. What is a CASE statement in T-SQL?

Answer-17: A conditional expression used to implement IF-ELSE logic inside SQL queries.



Question-18. How do you use a CASE statement in T-SQL?

Answer-18: SELECT Name, CASE WHEN Age > 18 THEN 'Adult' ELSE 'Minor' END AS Category FROM Users;



Question-19. What is COALESCE() in T-SQL?

Answer-19: A function that returns the first non-null value from a list.



Question-20. How do you find duplicate records in a table?

Answer-20: SELECT Column, COUNT(*) FROM Table GROUP BY Column HAVING COUNT(*) > 1;



Question-21. What is the difference between RANK(), DENSE_RANK(), and ROW_NUMBER()?

Answer-21: RANK() leaves gaps in ranking, DENSE_RANK() does not leave gaps, and ROW_NUMBER() provides unique numbers.



Question-22. How do you find the second highest salary using T-SQL?

Answer-22: SELECT MAX(Salary) FROM Employees WHERE Salary < (SELECT MAX(Salary) FROM Employees);



Question-23. What is a Common Table Expression (CTE) in T-SQL?

Answer-23: A temporary result set that can be referenced within a SELECT, INSERT, UPDATE, or DELETE query.



Question-24. How do you create a CTE in T-SQL?

Answer-24: WITH CTE AS (SELECT * FROM Table) SELECT * FROM CTE;



Question-25. What is a temporary table in T-SQL?

Answer-25: A table stored in tempdb and used within a session (#TempTable).



Question-26. What is a table variable in T-SQL?

Answer-26: A variable (@TableVariable) that stores a temporary result set like a table but exists only within a batch.



Question-27. How do you create a temporary table in T-SQL?

Answer-27: CREATE TABLE #TempTable (ID INT, Name VARCHAR(50));



Question-28. How do you create a table variable in T-SQL?

Answer-28: DECLARE @TableVar TABLE (ID INT, Name VARCHAR(50));



Question-29. What is the difference between HAVING and WHERE?

Answer-29: WHERE filters before aggregation, while HAVING filters after aggregation.



Question-30. What is an index in T-SQL?

Answer-30: A structure that improves query performance by reducing scan time.



Question-31. What are the types of indexes in T-SQL?

Answer-31: Clustered, Non-clustered, Unique, Full-text, Columnstore.



Question-32. How do you create an index in T-SQL?

Answer-32: CREATE INDEX idx_name ON Table(Column);



Question-33. What is a primary key in T-SQL?

Answer-33: A unique identifier for a table row (cannot contain NULL values).



Question-34. What is a foreign key in T-SQL?

Answer-34: A field in a table that references a primary key in another table.



Question-35. How do you add a primary key to a table?

Answer-35: ALTER TABLE Table ADD PRIMARY KEY (Column);



Question-36. How do you add a foreign key in T-SQL?

Answer-36: ALTER TABLE ChildTable ADD FOREIGN KEY (Column) REFERENCES ParentTable(Column);



Question-37. What is the IDENTITY property in T-SQL?

Answer-37: It generates auto-incrementing numbers for a column.



Question-38. How do you insert data into an identity column?

Answer-38: INSERT INTO Table (Name) VALUES ('John'); (ID auto-increments).



Question-39. How do you retrieve the last inserted identity value?

Answer-39: SELECT SCOPE_IDENTITY();



Question-40. How do you update data in T-SQL?

Answer-40: UPDATE Table SET Column = Value WHERE Condition;



Question-41. How do you delete a row in T-SQL?

Answer-41: DELETE FROM Table WHERE Condition;



Question-42. How do you use EXISTS in T-SQL?

Answer-42: SELECT * FROM Table WHERE EXISTS (SELECT 1 FROM OtherTable WHERE ID = Table.ID);



Question-43. What is the purpose of TRY...CATCH in T-SQL?

Answer-43: To handle runtime errors inside stored procedures.



Question-44. How do you implement TRY...CATCH in T-SQL?

Answer-44: BEGIN TRY -- SQL Code END TRY BEGIN CATCH -- Error Handling END CATCH;



Question-45. How do you fetch the first 10 records in T-SQL?

Answer-45: SELECT TOP 10 * FROM Table;



Question-46. How do you paginate results in T-SQL?

Answer-46: SELECT * FROM Table ORDER BY ID OFFSET 10 ROWS FETCH NEXT 10 ROWS ONLY;



Question-47. What is MERGE in T-SQL?

Answer-47: It allows INSERT, UPDATE, and DELETE in one statement based on condition.



Question-48. How do you use MERGE in T-SQL?

Answer-48: MERGE INTO TargetTable USING SourceTable ON Condition WHEN MATCHED THEN UPDATE SET Column = Value WHEN NOT MATCHED THEN INSERT (Column) VALUES (Value);



Question-49. How do you check SQL Server version using T-SQL?

Answer-49: SELECT @@VERSION;



Question-50. What is DBCC CHECKDB used for?

Answer-50: It checks database integrity and consistency.




Tags

Frequently Asked Question and Answer on Transact-SQL (T-SQL)

Transact-SQL (T-SQL) Interview Questions and Answers in PDF form Online

Transact-SQL (T-SQL) Questions with Answers

Transact-SQL (T-SQL) Trivia MCQ Quiz

FAQ Questions Sidebar

Related Topics


  • API Testing
  • Python
  • AWS Amazon Web Services
  • Java
  • C++
  • JavaScript
  • C#
  • PHP
  • Swift
  • Ruby
  • Kotlin
  • TypeScript
  • Go Golang
  • Rust
  • SQL
  • R
  • MATLAB
  • Perl
  • Scala
  • Dart
  • Haskell
  • Objective-C
  • Shell Scripting Bash
  • Visual Basic VB
  • Lua
  • Groovy
  • F#
  • Julia
  • COBOL
  • Fortran
  • Assembly Language
  • PL/SQL
  • Scratch
  • D
  • Erlang
  • Elixir
  • Clojure
  • Pascal
  • Ada
  • Lisp Common Lisp, Scheme
  • Prolog
  • Apex Salesforce
  • ActionScript
  • ABAP SAP
  • Racket
  • Nim
  • Crystal
  • Smalltalk
  • VHDL
  • Verilog
  • SASS Syntactically Awesome Style Sheets
  • Less CSS Preprocessor
  • CoffeeScript
  • J Sharp
  • Tcl (Tool Command Language)
  • XQuery
  • XSLT
  • OpenCL
  • CUDA
  • OpenGL Shader Language (GLSL)
  • VBScript
  • Solidity (Blockchain/Smart Contracts)
  • Yaml
  • JSON
  • XML
  • GDScript (Godot Engine)
  • UnrealScript (Unreal Engine)
  • Maple
  • Mathematica
  • Max/MSP
  • AutoLISP
  • LabVIEW
  • ScratchJr
  • AWK
  • sed (Stream Editor)
  • PostScript
  • Xojo
  • Q Sharp
  • Ring
  • ActionScript 3
  • OpenEdge ABL
  • RPG (IBM)
  • Inform
  • Modula-3
  • Rebol
  • Tcl/Tk
  • Haxe
  • SML (Standard ML)
  • Eiffel
  • Chapel
  • Red
  • MUMPS
  • PASCAL ABC
  • Icon
  • BCPL
  • Simula
  • SNOBOL
  • Hack (Meta)
  • PowerShell
  • Batch Script
  • AppleScript
  • Glue
  • Oz
  • Io
  • Mercury
  • Wren
  • Genie
  • PureScript
  • MoonScript
  • Turing
  • ALGOL
  • Seed7
  • Kotlin Native
  • Kotlin Multiplatform
  • Elm
  • PureBasic
  • QB64 (QuickBASIC)
  • Nemerle
  • Ocaml
  • Alloy
  • Cobra
  • Forth
  • Ballerina
  • Deno (JavaScript Runtime)
  • WASM (WebAssembly)
  • Z shell (Zsh)
  • Fish Shell
  • Redscript
  • Felix
  • ReScript
  • Agda
  • Idris
  • Coq
  • SPARK
  • Vala
  • PicoLisp
  • Wolfram Language
  • BASH (Bourne Again Shell)
  • Hy (Lisp-like for Python)
  • Terra
  • Boo
  • ATS
  • K (Kdb+)
  • Picat
  • Nimrod
  • Pawn
  • Papyrus (Bethesda Games)
  • J Programming Language
  • X++
  • MQL4/MQL5 (MetaTrader)
  • Transact-SQL (T-SQL)
  • BASH Shell Scripting

More Subjects


  • Computer Fundamentals
  • Data Structure
  • Programming Technologies
  • Software Engineering
  • Artificial Intelligence and Machine Learning
  • Cloud Computing

All Categories


  • Physics
  • Electronics Engineering
  • Electrical Engineering
  • General Knowledge
  • NCERT CBSE
  • Kids
  • History
  • Industry
  • World
  • Computer Science
  • Chemistry

Can't Find Your Question?

If you cannot find a question and answer in the knowledge base, then we request you to share details of your queries to us Suggest a Question for further help and we will add it shortly in our education database.
© 2025 Copyright InterviewQuizz. Developed by Techgadgetpro.com
Privacy Policy