Is it ok to name my database tables that are already keywords? For my case, I am trying to name the table that will hold my users. I've named it User but it is showing up as pink in SQL Server Management Studio so I am assuming its an existing System Table or Keyword. Thanks for your advice.
You can create tables with the same name as keywords. If you "quote" the table name it should work. The default quotes in SQL server are square brackets: []
CREATE TABLE [dbo].[user](
[id] [bigint] NOT NULL,
[name] [varchar(20)] NOT NULL
) ON [PRIMARY]
Yes, it is ok. In your queries, you can put [ and ] around your table name so that SQL Server knows you are referring to a table - i.e.
CREATE TABLE [User] ...
SELECT * FROM [User]
repeat this three times:
DO NOT DO IT, I WILL NOT USE RESERVED WORDS!
you'll thank me!
As mentioned, you can do it by quoting the name. Of course, you'll also have to quote the name anytime you reference it - trust me, it gets old real quick.
As an aside, just because SSMS syntax colors the word doesn't necessarily mean it's a reserved word. Sql can be annoying like that. ;)
Basic rule for table and column names (or better object names in general):
Don't use anything the same as, or even similar to, a reserved word. Only use A-Za-z0-9 and underscore. Especially don't use spaces. Only use names that don't require escaping, and then don't use escaping as a perpetual test.
You, and everyone who works with you, or will ever work on your code, don't need the aggravation.
I sit in the camp that says that table names should be plural, so in your case that would be Users.
I like this convention as it makes sense to me. You have a collection of users so call your table that. Further down stream if you pull out an indvidual row that could then populate an object named User.
If your convention dictates use of singular for table names use something different e.g.: Member, Client etc.
Also see RacerX's answer!
As previously mentioned it is tecnically OK if you [Braket] the name.
As everyone else has said don't do this; however, I was in the same boat. I have a rule that says all my tables are stored in singular form. Organization not Organizations, Asset not Assets a PartsCatalog has many Part etc.
Well I have a User table so what do I call it? I ended up escaping it [User]. Now I regret that decision because I am always forgetting to escape the table; however, I've not come up with a better name yet: Member is the leading candidate.