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?

#31Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 9:21:32 AM
Okay got you lol
#32ShubPosted 4/7/2014 9:23:02 AM
SinisterSlay posted...
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.


I said multi-field primary keys, not multiple primary keys :)
You can tell your table that the primary key is the concatenation of two fields.
---
-What is best in life?
-To crush your enemies, see them driven before you, and to hear the lamentation of the women.
#33Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 9:23:02 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. Looks like the prof is covering the former aspect, hopefully he's covering the latter at some point.


Yeah he went over that too with the Normal Forms iirc
#34SinisterSlayPosted 4/7/2014 9:23:19 AM
Maybe we should make this super convoluted to confuse your prof.

Like verifying recursively every field in the where clause using an inner select with multiple inner selects.
Oh, a using stored results from inner selects in outer selects :D
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#35SinisterSlayPosted 4/7/2014 9:25:52 AM(edited)
Shub posted...
SinisterSlay posted...
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.


I said multi-field primary keys, not multiple primary keys :)
You can tell your table that the primary key is the concatenation of two fields.


You can? That must be new since I learned about this stuff (or they didn't cover it). Is that in T-SQL?

Although I think someone should be shot if they do that, a primary key should never have any actual data in it. Like a common mistake, the SIN number as a primary key.
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#36Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 9:30:35 AM
SinisterSlay posted...
Maybe we should make this super convoluted to confuse your prof.

Like verifying recursively every field in the where clause using an inner select with multiple inner selects.
Oh, a using stored results from inner selects in outer selects :D


He'd probably give me a redo for that lol
#37SinisterSlayPosted 4/7/2014 9:39:29 AM(edited)
Tony_Biggie_Pun posted...
SinisterSlay posted...
Maybe we should make this super convoluted to confuse your prof.

Like verifying recursively every field in the where clause using an inner select with multiple inner selects.
Oh, a using stored results from inner selects in outer selects :D


He'd probably give me a redo for that lol


What if you do something like this?
http://www.codeproject.com/Tips/147331/Reading-Excel-file-in-SQL-Server
And use the excel file as the data source :D

I know all my profs were happy when I came up with really bizarre solutions that weren't covered by the text books.

My old Linux teacher used to congratulate us when we ruined the system so badly he couldn't fix it :D
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#38ShubPosted 4/7/2014 9:36:39 AM
SinisterSlay posted...
You can? That must be new since I learned about this stuff (or they didn't cover it). Is that in T-SQL?


I don't think it's that new, but it's not necessarily covered by learning materials. In SSMS you can just Ctrl+Click two fields, right-click and Set primary. Of course it's also supported directly in SQL.

http://technet.microsoft.com/en-us/library/ms191236(v=sql.90).aspx shows it's been supported since at least SQL Server 2005.
---
-What is best in life?
-To crush your enemies, see them driven before you, and to hear the lamentation of the women.
#39SinisterSlayPosted 4/7/2014 9:37:40 AM
Shub posted...
SinisterSlay posted...
You can? That must be new since I learned about this stuff (or they didn't cover it). Is that in T-SQL?


I don't think it's that new, but it's not necessarily covered by learning materials. In SSMS you can just Ctrl+Click two fields, right-click and Set primary. Of course it's also supported directly in SQL.

http://technet.microsoft.com/en-us/library/ms191236(v=sql.90).aspx shows it's been supported since at least SQL Server 2005.


I learned on 2000, so that's probably why
---
He who stumbles around in darkness with a stick is blind. But he who... sticks out in darkness... is... fluorescent! - Brother Silence
#40Tony_Biggie_Pun(Topic Creator)Posted 4/7/2014 11:53:19 AM(edited)
Ok. So now I'm almost done with this thing, but now I need to use the ALTER Table command to add a new constraint.

Is the syntax for this correct so far? I no that setting a foreign key could mess things up if done incorrectly so I'm just double checking

ALTER TABLE Visits
ADD Constraint CName
FOREIGN KEY(Customers.CName)REFERENCES
Customers(CName)
GO



EDIT: I see what the problem was. I had Customers.CName when I should really have CName by itself on line 3.