문제

I' trying to generate the scripts for ma DB in Sql Server 2008.. and i'm able to do that, the scripts generated is :

USE [Cab_Booking]
GO
/****** Object:  Table [dbo].[User]    Script Date: 05/19/2013 10:33:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[User]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[User](
    [U_Id] [int] IDENTITY(1,1) NOT NULL,
    [UserName] [nvarchar](50) NOT NULL,
    [Password] [nvarchar](50) NOT NULL,
    add column new int not null,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
    [U_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]
END
GO

What should i do if i need to add a new column in my table through scripts...

I know this sounds easy...But, i dont know what am i missing...

thanks..

도움이 되었습니까?

해결책

Right click on the table name on SQL Server Management Studio and select "Design". Then add a column using designer, but don't save. Right click anywhere on table designer and select "Generate Change Script". Now you have the script required to add new column to table. This method also works for removing columns, changing data types, etc.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top