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.
| Author |
Topic |
|
schoof_eas
Starting Member
4 Posts |
Posted - 2003-07-10 : 20:25:34
|
| Hey, this is my first time posting here. I submitted this question to the Ask Question section, but I figure it might also be better answered here. Basically, assume I have a table called "Items" that looks like this:CREATE TABLE Items AS( X int NOT NULL, Y int NOT NULL, Z int NOT NULL, o_id int NOT NULL)I also have a stored procedure that takes the values @xval, @yval, @zval, and @obj_id.You can imagine this table as storing a list of spacial coordinates along with a particular object at that location. Now, several items can be in the same plane (ie point(1,2,3) and point (2,2,2) are both on the same y plane) but no two items can be at the same point. If points (1,2,3) and (2,2,2) are already in the table, can I prevent another entry of (1,2,3) by using UNIQUE constraints somehow, or do I have to do a SELECT query first to see if that point already exists?Thanks in advance!-EricEdited by - schoof_eas on 07/10/2003 20:58:42 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-07-10 : 20:29:04
|
Just add a constraint to X, Y, Z:ALTER TABLE [dbo].[Items] WITH NOCHECK ADD CONSTRAINT [uniq_X_Y_Y] UNIQUE NONCLUSTERED ( [X], [Y], [Z] ) WITH FILLFACTOR = 90 ON [PRIMARY] GO Tara |
 |
|
|
schoof_eas
Starting Member
4 Posts |
Posted - 2003-07-10 : 20:39:52
|
| Ahh, thanks. I couldn't find any good examples of how to do this! |
 |
|
|
schoof_eas
Starting Member
4 Posts |
Posted - 2003-07-10 : 20:58:10
|
| I have one more question. I'm new to SQL, and I've been doing as much independant reading as I can, but some things still elude me. Say, in my previous example, that I want to add a whole bunch of items to my table (like several thousand). Do I have to do several thousand insert statements, or is there a way to pass an array of values into a procedure that would be faster?Thanks again, and sorry if this is a basic question. |
 |
|
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2003-07-10 : 21:01:46
|
| Here are several artile that talk about passing a delimited string into a stored proc and processing that string. I'm not sure which way is faster. You'll need to test both probably.http://www.sqlteam.com/SearchResults.asp?SearchTerms=csvMichael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
|
schoof_eas
Starting Member
4 Posts |
Posted - 2003-07-10 : 21:04:34
|
| Thanks, I appreciate it! Both the article, and putting up with me asking the question :-) |
 |
|
|
|
|
|
|
|