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
Windows Server 2008 R2: missing start menu of installed applications
Wireless AP network in a warehouse
Windows 2008 DC and IP Default Gateway settings
SBS 2008 - STOP c00002e2
split comma delimited values into seperate columns in SQL 2005
how to make background black?
Pass value on form through Querystring Javascript
Set up a rolling text box in SSRS
Video editing
Will there be a 13" Macbook with an iCore processor anytime soon? Safe to buy C2D?