How can I modify the following to add new filed without loosing existing data?

The new field I want to add is

[PageLocation] [nvarchar](50) NOT NULL,
without loosing the existing data.


USE [rightmatch]
GO

/****** Object:  Table [dbo].[MenuItem]    Script Date: 08/27/2013 16:53:57 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[MenuItem](
      [IDMenuItem] [bigint] IDENTITY(1,1) NOT NULL,
      [IDMembersRolesApps] [bigint] NULL,
      [MenuItemName] [nvarchar](50) NOT NULL,
      [MenuItemDescription] [nvarchar](255) NOT NULL,
 CONSTRAINT [SA_MenuItem_PrimaryKey] PRIMARY KEY CLUSTERED
(
      [IDMenuItem] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
goodkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kelvin SparksCommented:
ALTER TABLE dbo.MenuItem ADD
      PageLocation nvarchar(50)  DEFAULT (adefaultvalue) NOT NULL
GO

Kelvin
0
Tony303Commented:
Kelvin's example will locate the table at the bottom of the field list.

I would...
Backup the table first.

Right click the table in SQL Server Management Studio and choose Design.
You can then insert a new field anywhere you like.
You need to add a "Default Value or Binding" in the Column Properties.

Once you save this SQL will attempt to insert the field for you, filling in all the values with the default.

If the table is not too large it will do so without a timeout and you are good to go.

If however it is a large field, you may get a timeout.
You need to then look at the Menu, Table Designer, Generate Change Script.

Get this script and execute it in SQL Server Management Studio.
What it will do is copy the table temporarily elsewhere.
Deletes the data from the original table.
Puts in the new field to the original table.
Copy the contents from the "temp" into your table with the new field in it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodkAuthor Commented:
i did not understand what Tony is saying?
0
Tony303Commented:
Kelvins example will put the field here at the bottom...

     [IDMenuItem] [bigint] IDENTITY(1,1) NOT NULL,
      [IDMembersRolesApps] [bigint] NULL,
      [MenuItemName] [nvarchar](50) NOT NULL,
      [MenuItemDescription] [nvarchar](255) NOT NULL,
   [PageLocation] nvarchar(50) NOT NULL

My method will put it in anywhere you wanted using the SSMS GUI.
0
Tony303Commented:
Thanks for the points though
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.