Is there a coding naming convention principal for SQL variables? Can variables be named the same as column names, I heard in different companies, this may cause confusion. However in C# below, its a generally accepted principle, resource below.

create table dbo.Product
    ProductId int primary key null,
    ProductName varchar(25) not null,
    ProductDescription varchar(255) not null

create procedure dbo.ProductNameUpdate 
@ProductId int, @ProductName varchar(255)

update dbo.Product
ProductName = @ProductName
where ProductId = @ProductId 

https://msdn.microsoft.com/en-us/library/ms229060(v=vs.100).aspx https://www.dotnetperls.com/constructor

public Product(int ProductId, int ProductName)
            this.ProductId= ProductId;
            this.ProductName= ProductName;
  • Well, clearly variable names can be named the same as column names, as your example attests. There's no confusion (other than your odd choice of brace spacing), because the variables are always disambiguated, either by an @ sign or the this keyword. Jul 12 '18 at 0:28
  • I’ve never heard the term “brace spacing” @RobertHarvey and google failed me. What’s it referring to?
    – Paul
    Aug 12 '18 at 15:34
  • @Paul Indentation. Aug 12 '18 at 15:35
  • Oh, I assumed that was just a transcription error due to Stack’s code formatter.
    – Paul
    Aug 12 '18 at 15:36
  • Having database field names the same as their variable counterparts the same makes sense in an environment where the language or tools enforce additional chars on variable names. There is this same problem when you pass variables into a function with the same name as the variables local to the function. The long term question is maintenance time. How much time is lost as developers try to figure out or remember what's what. Aug 3 '21 at 22:47

Different languages have different naming conventions. For example, in Python fields should be formatted using snake case like product_id and product_name. If you ignore such conventions your code is going to be less idiomatic, and unless you use camel case for fields everywhere it is going to be inconsistent. Both of these will hurt readability. Of course, if you happen to only ever use a single language and a single database which happen to have the same naming conventions, go for it.


Not only is it acceptable to have column names the same as variables, most ORM tools will do so by default, following the naming conventions of whatever language is building the application.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.