MS SQL Server Dynamic SQl, T-SQL

MS SQL Server
Dynamic SQl, T-SQL

  • Mostly:

  • Dynamic SQL

  • Stored Procedure

  • Trigger

  • Cursor

  • Function

  • Sayed Ahmed

What are the Most Important
Most Used

  • Design ERD

  • Convert ERD to database

  • Normalization

  • Indexing

  • SQL

  • Stored Procedure

  • Dynamic SQL

  • These will come, not too frequent

  • Function, User Defined Data Types, Temporary Table

  • Trigger, Cursor

  • SSRS, SSIS, SSAS

  • ML in SQL Server (in advanced level)

  • May not be important initially

Today

  • More on

  • Dynamic SQL

  • Stored Procedure

  • Cursor

Basics of Stored Procedure

From Northwind Database

Dynamic SQL

  • DECLARE    @table NVARCHAR(128), @sql NVARCHAR(MAX);

  • SET @table = N'Products'

  • SET @sql = N'SELECT * FROM ' + @table;

  • EXEC sp_executesql @sql;

Convert the previous to a stored procedure

Using dynamic SQL to query from any table    of Northwind Database

Write a stored Procedure for it
table name as the parameter

Create or ALTER      Procedure    [dbo].[usp_query] ( @table NVARCHAR(128))
AS
BEGIN

Permanent link to this article: http://bangla.sitestree.com/ms-sql-server-dynamic-sql-t-sql/

Leave a Reply