This is a split board - You can return to the Split List for other boards.

Easier way to insert data into tables in SQL Server 2008?

#21SinisterSlayPosted 4/7/2014 8:38:16 AM
Tony_Biggie_Pun posted...
Yes thats exactly what I was trying to do. Thanks. So if I'm using NOT EXISTS with two Queries, I have to put the ORDER BY last?


Anything within () is an inner select. You can put them anywhere that an operation takes a parameter.

However, you should avoid inner selects when possible because they have a very heavy performance cost when used in applications
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#22Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 9:00:44 AM
What would be more efficient?
#23SinisterSlayPosted 4/7/2014 9:01:59 AM
Tony_Biggie_Pun posted...
What would be more efficient?


What are you trying to do, select all non null rows?
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#24Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 9:04:00 AM
I'm trying to select rows where the customers in the Customers table aren't in the visits table. Basically all of the customers that haven't visited a restaurant
#25SinisterSlayPosted 4/7/2014 9:06:49 AM(edited)
Tony_Biggie_Pun posted...
I'm trying to select rows where the customers in the Customers table aren't in the visits table. Basically all of the customers that haven't visited a restaurant


My SQL is very rusty but I think that is an inner join. But you should just be able to select from both tables.


Select Customers.CName
FROM Customers, Visits
WHERE Visits.CName = Customers.CName


Although using a name as a foreign key makes me itch. It would be better if there is a customer ID in the visits table.
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#26Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 9:13:00 AM
Yeah a customer ID would make sense. The professor wanted us to make the Names as the Primary Keys though because he wanted to show us examples of how two fields can be used to make one primary key . So we'd use a combination of Where the customer went to eat and the customers name as the key
#27SinisterSlayPosted 4/7/2014 9:14:24 AM(edited)
Tony_Biggie_Pun posted...
Yeah a customer ID would make sense. The professor wanted us to make the Names as the Primary Keys though because he wanted to show us examples of how two fields can be used to make one primary key . So we'd use a combination of Where the customer went to eat and the customers name as the key


Tell your prof you refuse to support bad database design. And that all code should be written as if the next person maintaining it is a homicidal maniac that knows where you live.
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#28Worknofun370Posted 4/7/2014 9:17:30 AM
SinisterSlay posted...
Tony_Biggie_Pun posted...
Yeah a customer ID would make sense. The professor wanted us to make the Names as the Primary Keys though because he wanted to show us examples of how two fields can be used to make one primary key . So we'd use a combination of Where the customer went to eat and the customers name as the key


Tell your prof you refuse to support bad database design.



This..

A key on Name-Restaurant is something that you would never do in real life, so you shouldn't do it in class either. Since someone with the same name as someone else could eat at the same restaurant.
#29ShubPosted 4/7/2014 9:19:56 AM(edited)
I find it important to know that you can do multi-field primary keys. It's useful in some scenarios. What matters is knowing when it's a bad idea. Looks like the prof is covering the former aspect, hopefully he's covering the latter at some point.
---
-What is best in life?
-To crush your enemies, see them driven before you, and to hear the lamentation of the women.
#30SinisterSlayPosted 4/7/2014 9:20:30 AM
Shub posted...
I find it important to know that you can do multi-field primary keys. It's useful in some scenarios. What matters is knowing when it's a bad idea.


Do you mean multiple foreign keys?
Pretty sure you can't have multiple primary keys.
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence