当前位置: 代码迷 >> PB >> 怎么写这样的索引
  详细解决方案

怎么写这样的索引

热度:28   发布时间:2016-04-29 09:03:43.0
如何写这样的索引?
id,name,departmentid,idcard,creditDocNo,type
1,'王红',12,'522501198201153614',1,'A照'
2,'王红',12,'522501198201153614',1,'B照'
3,'张某',2,'522530195703022938',2,'E照'
4,'前红',3,'522501196207032013',3,'N照'
说明,我的ID是自动生成,我的要求限制是我一个departmentid下面,一个idcard只能有一个creditDocNo,这样的索引怎么写?CREATE UNIQUE INDEX [in_departmentid_creditDocNo] ON [dbo].[dt_career]([departmentID], [creditDocNo],[idcard]) ON [PRIMARY]
GO
我写的再个是提示错误的

------解决方案--------------------
SQL code
--试试CREATE UNIQUE NONCLUSTERED INDEX [IX_tb3] ON [dbo].[tb] (    [departmentid] ASC,    [idcard] ASC,    [creditDocNo] ASC)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]
------解决方案--------------------
CREATE UNIQUE NONCLUSTERED INDEX [IX_tb3] ON [dbo].[dt_career] 

[departmentid] ASC, 
[idcard] ASC, 
[creditDocNo] ASC 
)
------解决方案--------------------
探讨
1,'王红',12,'522501198201153614',1,'A照'
2,'王红',12,'522501198201153614',1,'B照'
过不了在种数据

------解决方案--------------------
探讨
同一个IDCARD,必须是同一个creditDocNo
  相关解决方案