Augument a table with several attributes

I need to add theses

[ServiceID] [int]  - (the new way links to a company service)
[FlagRemoved] [bit] NULL DEFAULT ((0))
[AgentRemoved] [nvarchar](50)
[DateRemoved] [datetime]

to the following table.
CREATE TABLE [dbo].[tbl_index_ticket_services](
      [IndexTicketServiceID] [int] IDENTITY(1,1) NOT NULL,
      [TicketID] [int] NULL,
      [ServiceTypeID] [int] NULL,
      [DateAdded] [datetime] NULL,
      [AgentAdded] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
      [DateCreated] [datetime] NULL,
 CONSTRAINT [PK_tbl_index_ticket_services] PRIMARY KEY NONCLUSTERED
(
      [IndexTicketServiceID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
mathieu_cuprykAsked:
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.

rob_farleyCommented:
alter table [dbo].[tbl_index_ticket_companies]
add
[ServiceID] int,
[FlagRemoved] bit NULL DEFAULT ((0)),
[AgentRemoved] [nvarchar](50),
[DateRemoved] [datetime] ;

You may want to also create a foreign key to the Service table...

alter table [dbo].[tbl_index_ticket_companies]
add constraint fk_Ticket_Service foreign key (ServiceID)
    references dbo.Services (ServiceID) ;


Hope this helps,

Rob
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
mathieu_cuprykAuthor Commented:
awesome job.
0
mathieu_cuprykAuthor Commented:
where did u get tbl_index_ticket_companies?


should it be tbl_index_ticket_services?
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

mathieu_cuprykAuthor Commented:
we have to undo this

alter table [dbo].[tbl_index_ticket_companies]
add
[ServiceID] int,
[FlagRemoved] bit NULL DEFAULT ((0)),
[AgentRemoved] [nvarchar](50),
[DateRemoved] [datetime] ;

alter table [dbo].[tbl_index_ticket_companies]
add constraint fk_Ticket_Service foreign key (ServiceID)
    references dbo.tbl_Services (ServiceID) ;
0
rob_farleyCommented:
Oh, sorry... I had read it as being the same table as in the other question. Yes, it should be tbl_index_ticket_services

Did extra columns get created in tbl_index_ticket_companies that you didn't want?

To remove the constraint, use "drop" instead of "add".

alter table [dbo].[tbl_index_ticket_companies]
drop constraint fk_Ticket_Service

And I'm not sure what the table is you need to hook into for your foreign key (if you actual require one at all).

Rob
0
rob_farleyCommented:
And to drop a column:

alter table [dbo].[tbl_index_ticket_companies]
drop column [ServiceID];
0
mathieu_cuprykAuthor Commented:
what about the constraint?
0
mathieu_cuprykAuthor Commented:
Msg 5074, Level 16, State 1, Line 1
The object 'fk_Ticket_Service' is dependent on column 'ServiceID'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN ServiceID failed because one or more objects access this column.

we must delete the fk and the column.
0
rob_farleyCommented:
Yup... so drop the FK first (see my other comment), and then you can drop the column.

Rob
0
rob_farleyCommented:
ie:

alter table [dbo].[tbl_index_ticket_companies]
drop constraint fk_Ticket_Service;
go
alter table [dbo].[tbl_index_ticket_companies]
drop column [ServiceID];
go
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
Microsoft SQL Server 2005

From novice to tech pro — start learning today.