mathieu_cupryk
asked on
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_se rvices](
[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_servi ces] 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]
[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_se
[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_
[DateCreated] [datetime] NULL,
CONSTRAINT [PK_tbl_index_ticket_servi
(
[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]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
where did u get tbl_index_ticket_companies ?
should it be tbl_index_ticket_services?
should it be tbl_index_ticket_services?
ASKER
we have to undo this
alter table [dbo].[tbl_index_ticket_co mpanies]
add
[ServiceID] int,
[FlagRemoved] bit NULL DEFAULT ((0)),
[AgentRemoved] [nvarchar](50),
[DateRemoved] [datetime] ;
alter table [dbo].[tbl_index_ticket_co mpanies]
add constraint fk_Ticket_Service foreign key (ServiceID)
references dbo.tbl_Services (ServiceID) ;
alter table [dbo].[tbl_index_ticket_co
add
[ServiceID] int,
[FlagRemoved] bit NULL DEFAULT ((0)),
[AgentRemoved] [nvarchar](50),
[DateRemoved] [datetime] ;
alter table [dbo].[tbl_index_ticket_co
add constraint fk_Ticket_Service foreign key (ServiceID)
references dbo.tbl_Services (ServiceID) ;
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_co mpanies]
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
Did extra columns get created in tbl_index_ticket_companies
To remove the constraint, use "drop" instead of "add".
alter table [dbo].[tbl_index_ticket_co
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
And to drop a column:
alter table [dbo].[tbl_index_ticket_co mpanies]
drop column [ServiceID];
alter table [dbo].[tbl_index_ticket_co
drop column [ServiceID];
ASKER
what about the constraint?
ASKER
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.
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.
Yup... so drop the FK first (see my other comment), and then you can drop the column.
Rob
Rob
ie:
alter table [dbo].[tbl_index_ticket_co mpanies]
drop constraint fk_Ticket_Service;
go
alter table [dbo].[tbl_index_ticket_co mpanies]
drop column [ServiceID];
go
alter table [dbo].[tbl_index_ticket_co
drop constraint fk_Ticket_Service;
go
alter table [dbo].[tbl_index_ticket_co
drop column [ServiceID];
go
ASKER