Solved

bcp is not following the check constraint

Posted on 1998-08-25
2
599 Views
Last Modified: 2006-11-17
Hi,

I have a check constraint on several columns of integers.  When I use bcp, even when the values being imported are outside the specified domain, bcp imports them in just fine.
When I use an insert statement manually, the constraints are enforced, so I don't think it's my syntax.

How can I get bcp to follow the check constraints and not go outside my desired domain?

A part of my create table statement:
num_5000   INTEGER   NOT NULL
    CHECK (num_5000 BETWEEN 0 and 708),

The bcp command for a tab delimited ASCII text file:
bcp chiptray..core_data in temp.txt /SSERVER /Usa /Pxxx /c

And finally, bcp is called from within a batch file.

Thanks.  :-)
0
Comment
Question by:atclark
2 Comments
 
LVL 3

Accepted Solution

by:
gmoriak earned 50 total points
ID: 1089745
I'm sorry, but BCP can't be made to check constraints.

BCP is so quick because it ignores things like constraints and triggers.  You have three options as I've learned.

1.  BCP into an alternate table and create a process to transfer items to your real table.  This process (sp, insert/select,  etc.) will use the constraints.
2.  Create a process to check and report constraint violations after BCP.
3.  Say oh well and live with constraint violations or change the process that creates the input file to enforce constraints so there are no problems
0
 

Author Comment

by:atclark
ID: 1089746
Thank you.  That's exactly the information I needed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now