Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 unique constraint

Author  Topic 

taowang
Starting Member

6 Posts

Posted - 2007-12-03 : 17:16:08
Hi,

I have a table with two column, c1 and c2. c1 is set as primary key. I want c2 to be set with unique constraint.

I choose this talbe in object explorer, right click and select modify. Then I choose "index/key" from "table designer" menu.

The problem is that in the "index/key" dialog, the "Columns" item (under General) is always c1. if I click the "..." button to popup "index column", I could only choose either "c1" or <None> under "column name" dropdownlist.

How could I choose c2 and set unique constraint on it?

Thx
Tao

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-12-03 : 17:24:24
You could script it out or on the Index/Keys Dialog on the Columns property if you click on the Columns ot c1 you should get a picker(three dots) button. Click on that then you will get the Index Columns Dialog. From there you should be able to select c2 in the column dropdown.
Go to Top of Page

taowang
Starting Member

6 Posts

Posted - 2007-12-03 : 20:48:08
Here is the script:

USE [SmartyRunResults]
GO
/****** Object: Table [dbo].[Run] Script Date: 12/03/2007 17:46:51 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Run](
[RunID] [uniqueidentifier] NOT NULL,
[SmartyDOTXMLFilePath] [nvarchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
CONSTRAINT [PK_Run] PRIMARY KEY CLUSTERED
(
[RunID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

c2 is in fact SmartyDOTXMLFilePath. I begin to wonder if it is due to its type [nvarchar](max)
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-12-04 : 11:35:07
Yes, NVARCAHR(MAX) is your issue. From BOL: "The maximum allowable size of the combined index values is 900 bytes."
Go to Top of Page
   

- Advertisement -