How to Alter Columns or Generate Alter Scripts by using GUI in SQL Server - SQL Server / T-SQL Tutorial Part 38

Scenario:

You are working as SQL Server developer for Law Firm. You have created table customer in one of the Database "TechBrothersIT" by using below Script.

CREATE TABLE [dbo].[Customer](
    [FirstName] [varchar](50) NULL,
    [LastName] [varchar](50) NULL,
    [Age] [tinyint] NULL,
    [PhoneNumber] [char](9) NULL,
    [DOB] [date] NULL,
    [Sex] [char](1) NULL
)

You need to make below changes to dbo.Customer but don't want to write scripts by yourself. You want to use Graphical User Interface to generate these script or even make those change right away.

Change Sex Column Name to Gender
Change First Name to FName
Change LastName to LName and Max size to Varchar (30)


Solution:

Step 1:
Go to Database and then go to Tables tab. Once you see your required table, Right Click and hit Design.
How to generate Alter Script or Alter Table in Design Mode in SQL Server Management Studio


Step 2:
Once you hit Design, Design window will open. Start making changes as per your requirement.
How to Alter Table in SQL Server by using Design Windows - SQL Server Tutorial



Step 3:
Now you have two options, You can hit Save button and all changes will be saved. If you would like to generate scripts so you can use in DEV, QA , UAT and Prod. You can click on Generate Script Button and it will generate scripts for you.

How to generate Alter script for table from Design Windows in SQL Server - T-SQL Tutorial




Once you hit Generate Script Button, below window will open and you can save the scripts to file to use in any environment.
How to generate Modify Columns in SQL Server Table from Design Windows - T-SQL Tutorial



Video Demo : Generate Alter Column statements from Graphical user interface in SQL Server

1 comment: