Skip to content
Advertisement

What are the use cases for selecting CHAR over VARCHAR in SQL?

I realize that CHAR is recommended if all my values are fixed-width. But, so what? Why not just pick VARCHAR for all text fields just to be safe. Answer The general rule is to pick CHAR if all rows will have close to the same length. Pick VARCHAR (or NVARCHAR) when the length varies significantly. CHAR may also be a

performing datetime related operations in PHP

How do you actually perform datetime operations such as adding date, finding difference, find out how many days excluding weekends in an interval? I personally started to pass some of these operations …

How can you handle an IN sub-query with LINQ to SQL?

I’m a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL: Any help would be gratefully received. Answer Have a look at this article. Basically, if you want to get the equivalent of IN, you need to construct an inner query first, and then use the Contains() method. Here’s my

RegEx to Detect SQL Injection

Is there a Regular Expression that can detect SQL in a string? Does anyone have a sample of something that they have used before to share?

SQL Server – Best way to get identity of inserted row?

What is the best way to get IDENTITY of inserted row? I know about @@IDENTITY and IDENT_CURRENT and SCOPE_IDENTITY but don’t understand the pros and cons attached to each. Can someone please explain the differences and when I should be using each? Answer @@IDENTITY returns the last identity value generated for any table in the current session, across all scopes.

Advertisement