Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 change columkn size

Author  Topic 

jassie
Constraint Violating Yak Guru

332 Posts

Posted - 2012-08-06 : 11:01:59
In a sql server 2008 r2 database, I am changing the size of a column called NOTES from varchar(500) to varchar(max). When this occurs, I lose the foregin key and relationships to other tables.

Basically when I run the script below in sql server management studio 2008 r2, everything runs fine. However when I right click on the 'proc' table in sql server management studio and select, 'script table as'-->create to-->new query edit window, I lose the relationship to the other tables.

Thus can you tell me if I am really losing the relationship to the tables and why this is occuring? Is the field called 'notes' used as part of the index?

If I am not losing the relationship of the 'proc' table to the other tables, can you tell me why sql server studio 2008 r2 is not showing the relationship to the other tables?

The following is the script I am referring to:


SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Proc](
[Proc_ID] [int] IDENTITY(1,1) NOT NULL,
[Excep_ID] [int] NULL,
[NOTES] [varchar](max) NULL
CONSTRAINT [PK_Proc] PRIMARY KEY CLUSTERED
(
[Process_Transaction_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]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Proc] WITH CHECK ADD CONSTRAINT [FK_Proc_Doc] FOREIGN KEY([Doc_ID])
REFERENCES [dbo].[Doc_Review] ([Doc_ID])
GO

ALTER TABLE [dbo].[Proc] CHECK CONSTRAINT [FK_Process_Transaction_Documentation_Review_6]
GO

ALTER TABLE [dbo].[Proc] WITH CHECK ADD CONSTRAINT [FK_Proc_Enroll FOREIGN KEY([Enroll_ID])
REFERENCES [dbo].[Enrol_Mech] ([Enrol_Mech_ID])
GO

ALTER TABLE [dbo].[Proc] CHECK CONSTRAINT [FK_Proc_Enroll_Mech]
GO

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-08-06 : 11:14:30
for modifying a column length why should you script out table?

isnt it enough to fire a ALTER TABLE ALTER COLUMN statement?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -