Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB.net SQL Not at allowing duplicates in a field

Posted on 2014-10-02
11
103 Views
Last Modified: 2014-10-07
Hi
I use the following VB code to create a SQL table.
How do I change the code so that the column [BANK ID] does not allow duplicates


Sub Create_Table_Payments()

On Error GoTo EH

DeleteTableADO ("PAYMENTS")

Dim sSQL As String

sSQL = "CREATE TABLE [PAYMENTS] "
sSQL = sSQL & "([ID] bigint identity(1,1) not null primary key, [LINK ID] bigint,  "
sSQL = sSQL & "[DATE] datetime, [AMOUNT] decimal(12,2), "
sSQL = sSQL & "[DETAILS] nvarchar(MAX), [PMT TYPE] nvarchar(40), [TRANS TYPE] nvarchar(40),[BANK BAL] decimal(12,2), [BANK ID] bigint)"
'/// NEW
Call oCreate_Online_Table(sSQL)
Exit Sub
EH:
MsgBox Err.Description

End Sub
0
Comment
Question by:murbro
  • 4
  • 2
  • 2
  • +3
11 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40358784
what is considered "a duplicate" in this table?

are you saying that you can only EVER have ONE PAYMENT per bank?
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40358798
just observations,
[DATE] isn't a great field name as the word date used by Tsql,
defining field names that contain spaces is possible but is a nuisance from day 1 (use an underscore perhaps?)
0
 
LVL 12

Expert Comment

by:James Elliott
ID: 40358818
I would add an index.

CREATE UNIQUE NONCLUSTERED INDEX [nondupe] ON dbo.[PAYMENTS] 
(
	[BANK ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO

Open in new window

0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 48

Expert Comment

by:Vitor Montalvão
ID: 40358837
@PortletPaul said:
are you saying that you can only EVER have ONE PAYMENT per bank?
And if it's that you really want to achieve, why the data type is bigint? How many banks do you have there?
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40358846
LOL
una carga de cubo de los bancos? un cubo grande de los bancos!
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 40362754
I suspect something got lost in translation or we are confusing Spanish with Portuguese.  :)
0
 

Author Comment

by:murbro
ID: 40364520
[BANK ID] stores the unique ID number of a bank transaction so I don't want that transaction  reflecting twice in my payments table
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 40364550
Set it to Not Null and Unique

http://www.w3schools.com/sql/sql_unique.asp
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40365170
I shall leave this question now, there are many suggestions on how to make a field unique.
Use a message if you think I can contribute meaningfully here.

I just don't think you should make that field unique, it does not make sense.
0
 
LVL 48

Expert Comment

by:Vitor Montalvão
ID: 40365322
[BANK ID] stores the unique ID number of a bank transaction so I don't want that transaction  reflecting twice in my payments table
So, is not really the ID from a bank, right?
If so you should change the column name to TransactionID because like this it's making a lot of confusion to us.
0
 

Author Closing Comment

by:murbro
ID: 40365388
Thanks very much for stepping in here. I was looking for a simple answer. Apologies to everyone else if I confused the issue.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question