Automatically generate a SELECT statement in SQL Server Management Studio for a table example


By:

Overview
From your previous examples, I want to find out how to get SQL Server Management Studio (SSMS) to do the work for me.  How can I have this tool generate a SELECT statement rather than typing out each of the columns?

Explanation
SQL Server Management Studio does have a simple means to automatically generate a SELECT statement from a single table.  Let's follow the steps below:

Once you are in SQL Server Management Studio, right click on the table you which you would like to have the SELECT statement generated for.

toGenerateSelectStatement 1

On the subsequent interface, select the 'Script Table as' option.

toGenerateSelectStatement 2

On the subsequent interface, select the 'SELECT To' option.

toGenerateSelectStatement 3

On the subsequent interface, select the 'New Query Editor Window' option.

toGenerateSelectStatement 4

Below is a sample image of the SELECT code generated for a table.

toGenerateSelectStatement 5






Comments For This Article




Monday, April 24, 2017 - 8:11:14 AM - JEAN MBADI Back To Top (55131)

Hello again Jeremy,

 

As per the previous comment, here's the statement SELECT statement of the table

 

USE [AdventureWorks2016]

GO

 

SELECT [BusinessEntityID]

      ,[NationalIDNumber]

      ,[LoginID]

      ,[OrganizationNode]

      ,[OrganizationLevel]

      ,[JobTitle]

      ,[BirthDate]

      ,[MaritalStatus]

      ,[Gender]

      ,[HireDate]

      ,[SalariedFlag]

      ,[VacationHours]

      ,[SickLeaveHours]

      ,[CurrentFlag]

      ,[rowguid]

      ,[ModifiedDate]

  FROM [HumanResources].[Employee]

GO

 

Hence, you can see that in Adventureworks2016, there's no EmployeeID

 

Regards















get free sql tips
agree to terms