Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Table and Column Name Same ???

Author  Topic 

prashant_akerkar
Starting Member

5 Posts

Posted - 2010-04-07 : 02:41:15

Are there any specific disadvantages if i create a table and define a column by same name as it allows me to create ?

Say by Using Joins with other tables, index creating etc, can it give me incorrect results ?

For example :

Table Name : Books
Column Name : Books , Primary Key, Numeric Not Null ?


i can also use the select query :

select books from books;


Awaiting your Reply,

Thanks & Regards,
Prashant S Akerkar

Asken
Starting Member

38 Posts

Posted - 2010-04-07 : 03:23:54
Well, the obvious disadvantage is that it would be hard to read. There is nothing preventing you from doing it but I would say it's bad practice.

SQL Server will allow for you to create such a table and it will also keep the table and column separated in joins and all other stuff. You can even use reserved words as columns and tables and SQL Server will keep it separated... (not recommended either though) :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 03:31:42
You can do that with no problem as Asken already told.
But in your example I would prefer the column name as BooksId because that's what it is.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

prashant_akerkar
Starting Member

5 Posts

Posted - 2010-04-07 : 04:22:18
Thank you.

Thanks for the Answers provided from your side.

As you mention "it's a bad practise but there will be no problem in getting incorrect results from Joins with this table with other tables" can i add the following comment from my side :
As we have coding standards for programming languages (say Java, C#, C++ etc) which we do follow

Can we can add the above in Relational Database Management System Designing Standards ?

i.e Avoid Table and Column / Field having the same name as its not a good practice.


Thanks & Regards,
Prashant S Akerkar
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-07 : 04:25:24
You can but it is your own decision.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

prashant_akerkar
Starting Member

5 Posts

Posted - 2010-04-07 : 05:28:06
Thank you

I researched for "Relational Database Designing Standards" in Google
search engine.

Looks a Good Link for Sharing

http://it.toolbox.com/blogs/enterprise-solutions/sample-design-amp-development-standards-for-rdbms-37349

Thanks & Regards,
Prashant S Akerkar
Go to Top of Page

Asken
Starting Member

38 Posts

Posted - 2010-04-07 : 05:39:25
Follow whatever design you decide on and be consistent.

Personally i almost never tag object names with a sql server object type like tab_Customer. I know it's a table and I don't access tables directly from application so it's never a problem.

Reporting & Analysis Specialist
Go to Top of Page
   

- Advertisement -