Solved

VB.net SQL Not at allowing duplicates in a field

Posted on 2014-10-02
11
99 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 47

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 47

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

777 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