Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAr33ss Leon
4,621 PointsShould all databases attributes(data types) be put to MAX?
I am just asking if it is a good practice to put attributes to MAX and then you limit them in the programming side. I have good knowledge about databases but I have ZERO knowledge about good practices. In this video I noticed the context creates a database with MAX varchars and then you have to limit it, but I am wondering what if I try to make my own database in sqlserver.
2 Answers
KRIS NIKOLAISEN
54,971 Pointsfrom Microsoft docs
If you use nchar or nvarchar, we recommend to:
- Use nchar when the sizes of the column data entries are consistent.
- Use nvarchar when the sizes of the column data entries vary considerably.
- Use nvarchar(max) when the sizes of the column data entries vary considerably, and the string length might exceed 4,000 byte-pairs.
Allan Clark
10,810 PointsTo add on to Kris's answer, the best practice for this is to have the Entity Framework attribute mirror the database column as closely as possible. The video shows what is created by default with no attributes, then adjusts the code to show the effects of adding the attributes.