views:

32

answers:

3

I have to have a table that saves information about a Course in my university.

I need to save the name of the course, the month it's going to be open, and also the time.

What built in Microsoft SQL server datatypes should I use? I'll be using Linq2SQL as my ORM.

+1  A: 
int for ID
string for Course_Name

since you're using SQLS2K8 you can split DATE and TIME fields so..

Date for Opening_Month
Time for Opening_Hour
Eton B.
+1  A: 

varchar if the names can be ascii only, nvarchar for unicode names, date for month and time for time. The ones that look like this are the SQL Server types

SQLMenace
A: 

If you only need the month(not date or year) and the time, then you could use an int for the month, and a Time for the time. You could also use the DateTime instead and just work out a convention that ignores the date and year aspect of the date.

I would recommend nvarchar or varchar for the name. Use nvarchar if you anticipate there ever being a point in the future that you will need to support foreign languages that might contain unicode characters that are not supported by varchar. I would look at the longest name I anticipate needing, double it's length and then round up to the nearest 50. So if "Introduction to Partial Differential Equations" at 48 then I would make it varchar(100).

The purpose of making it so much larger is to allow for future values. If I only made it varchar(48) to accomdate the current largest value, I might later have a coursename that's larger than that, and thus would have to modify the database structure and the applications to accomdate this larger size! By making it varchar(100) we have plenty of room for larger course names that might occur in the future.

AaronLS
That is incorrect! varchar(50) and nvarchar(50) both store 50 characters, but nvarchar will use 100 bytes per storage. Here is an example that stores 1 character, no need to make it nvarchar(2).....declare @n nvarchar(1) set @n = N'文'select @n. This is also a reason you can't do this declare @n nvarchar(5000) but you can do this declare @n varchar(5000)
SQLMenace
@SQLMenace I know all this and did not state anything that contradicts it. Did you even read my post or are you just trolling? What is incorrect? Quote me where I make an incorrect statement please.
AaronLS
@SQLMenace Maybe you are confused about why I doubled the length. The reason I do that is because to allow for future values that are larger than current values. "Introduction to Partial Differential Equations" may be the current longest value, but the application may encounter longer values in the future. Without knowing for sure what you will encounter, I simply take existing data, double the max length to get a good data size with plenty of room for larger values that may occur in the future. This is pretty common practice and I'm surprised you're not familiar with it.
AaronLS
Looks like I misread your answer..I thought you meant doubling when using nvarchar........sorry..not trolling
SQLMenace
Sounds good. I will edit to make more clear.
AaronLS

related questions