Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to come up with a script for modifying an existing table in the database without losing the existing information?
    primarykey
    data
    text
    <p>I have an application with a database which they are working well and everything is fine. </p> <p>Now, I just need to modify one table in the database by adding more columns to it. I am using SQL Server and the database administrator asked me to provide him with the script of modifying that table. </p> <p><strong>So how to do that?</strong> </p> <p>I am using SQL Server Management Studio and when I click on the table right-click, I used to select script to create, and Management Studio will give me the script. Now, this table has information, so I think I should not use create script for this table. </p> <p>The new columns should allow null values. </p> <p><strong>So what should I use?</strong></p> <p>For your information, here is the script for creating the table:</p> <pre><code>SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Test]( [ID] [numeric](18, 0) IDENTITY(1,1) NOT NULL, [No] [char](20) NOT NULL, [Date] [smalldatetime] NULL, [ProjectType] [char](500) NULL, [ProjectPhase] [char](300) NULL, [rejected_reason] [varchar](max) NULL, [archived_reason] [varchar](max) NULL, [forward_to] [varchar](max) NULL, [forward_type] [varchar](max) NULL, [forward_concern] [varchar](max) NULL, CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO SET ANSI_PADDING OFF GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLATestB_No] DEFAULT ('*') FOR [No] GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLATestB_Status] DEFAULT ((2)) FOR [Status] GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLATestB_AID] DEFAULT ((0)) FOR [AID] GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLATestB_Hit] DEFAULT ((0)) FOR [Hit] GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLATestB_Sent] DEFAULT ((0)) FOR [Sent] GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLATestB_SentTo] DEFAULT ((0)) FOR [SentTo] GO ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_LLa_Added_To_Cart] DEFAULT ((0)) FOR [Added_To_Cart] GO </code></pre> <p>Examples of the new columns that should be added to this table are:</p> <pre><code>[rejected_reason] [varchar](max) NULL, [archived_reason] [varchar](max) NULL, [forward_to] [varchar](max) NULL, [forward_type] [varchar](max) NULL, </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload