change column size

  • I must be missing something, or this script must be missing something.

    First, the primary key constraint is on a column that's not in the table definition.

    Same for each of the FK constraints - they're from columns that aren't in the table definition.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • There are foreign keys referenced in the below script, SSMS just scripts them as ALTERS rather than in-line with the table definition. For e.g. this is a Foreign Key definition:

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

    REFERENCES [dbo].[Enrol_Mech] ([Enrol_Mech_ID])

    GO

    However, you've shown us a script that re-creates a table from scratch (presumably losing all your existing data). If you just want to change the data type to a new type that's a subset of the existing data (such as changing from varchar(n) to varchar(max)), then you should use the ALTER TABLE...ALTER COLUMN syntax. E.g.:

    ALTER TABLE [PROC]

    ALTER COLUMN Notes VARCHAR(MAX) NULL

  • Thought of a possibility. Are you modifying the column by dropping and re-creating the table, or by using the table designer GUI, or by issuing a simple Alter Table script?

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • I am just giving you an example of the sql that is generated by the ssms. if there is sql problems, I just showed you an example, since I am not suppose to show the real data names.

    Thus can you just answer my question?

  • wendy elizabeth (8/6/2012)


    I am just giving you an example of the sql that is generated by the ssms. if there is sql problems, I just showed you an example, since I am not suppose to show the real data names.

    Thus can you just answer my question?

    Nope.

    There is no way to tell what's wrong with a database script that I can't look at.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • wendy elizabeth (8/6/2012)


    Thus can you just answer my question?

    Well, we've both tried to do so, but your question isn't clear. You've stated you're trying to alter a column, but you've posted a CREATE TABLE script instead. You've stated that the relationships to other tables have been 'lost', but there are relationships to other tables in the script.

    Until you provide more information, I'm not sure how anyone can help further...

  • I found out what my problem is. Thanks everyone!

Viewing 7 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply