Efficient way to do select * form [TableName]

For selecting data from any table in sql server we have to do select * form [TableName] all the time.
But we can do this in a smart way with key combinations.

Step 1:

Create a stored procedure in master table.

USE [Database Name]
GO

/****** Object: StoredProcedure [dbo].[sp_tabledata]******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[sp_tabledata] @objname NVARCHAR(MAX) = NULL
AS
SET NOCOUNT ON

DECLARE @query NVARCHAR(MAX)

IF @objname IS NOT NULL
BEGIN
SET @query = N'SELECT * FROM ' + @objname
EXEC (@query)
END
ELSE
BEGIN
PRINT 'No data present on table'
END
RETURN (0)

Step 2:
Execute the stored procedure and go to the tools menu.
Select options menu
options -> keyboard -> QueryShortcuts -> choose the shortcut you like and paste the stored proc name
in my case it is ctrl+5 and sp_tabledata

Step 3:

You are good to go now. Just close sql server and open again.
type any table name and then apply the shortcut you want.
You will get all the data from that table you want.


Leave a Reply

Your email address will not be published.