Microsoft
Software
Hardware
Network
Question : sql column that represents a unique tag number
We have a table with a column that represents a unique tag number [INumber]. We created a CREATE UNIQUE NONCLUSTERED INDEX on it and we want to add a contraint that will take the identify column as its default value. How can we do this?
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ATable]
') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[ATable]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[ATable](
[ID] [int] IDENTITY(1,1) NOT NULL,
[IName] [nvarchar](500) NOT NULL,
[INumber] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_ATable] PRIMARY KEY CLUSTERED
(
[ID] 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]
GO
ALTER TABLE [dbo].[ATable] WITH NOCHECK ADD
CONSTRAINT [DF_ATable_IName] DEFAULT ('') FOR [IName]
GO
CREATE UNIQUE NONCLUSTERED INDEX [UIX_ATable_INumber] ON [dbo].[ATable]([INumber]) ON [PRIMARY]
GO
Answer : sql column that represents a unique tag number
You could use a TRIGGER for INSERT that updated this field to value of ID if it is NULL.
Random Solutions
How to reduce DASD utilization
Cannot tracert beyond DSL modem
Exception processing does not intersept error.
Windows SBS 2003
Continuous Forms colour change by time
Microsoft Outlook 2010 Error
Best Software Environment to create Image / Designs / Templates for Websites
Mac RDP clients slow?
Lotus Agent to save attachment
How to update & append at the same time from another table a table in SQL Server