开发者

Can't create a table called State in SQL Server?

I want to save a list of States in my database. But it seems I can't call it 'State'. Intellisense in SQL Management Studio colors it differently.

Is this a correct assumption and I should call it somethi开发者_运维问答ng else?

create table Category
(
    ID int primary key identity(1,1),
    Name nvarchar(256) not null
)

go

create table Subcategory
(
    ID int primary key identity(1,1),
    Name nvarchar(256) not null,
    IDCategory int foreign key references Category(ID)
)

go

create table Advert
(
    ID int primary key identity(1,1),
    IDAdvertiser int foreign key references Advertiser(ID),
    IDSubcategory int foreign key references Subcategory(ID),
    ImagePath nvarchar(2048) not null,
    StartDate datetime not null,
    FinishDate datetime
)

go

create table Advertiser
(
    ID int primary key identity(1,1),
    Name nvarchar(2048) not null,
    Contact nvarchar(256) not null,
    Website nvarchar(256) not null
)

go

create table State


Call it [State] to avoid conflicting with system reserved words. Though in most cases, that is not neccessary, the parser is usually smart enough to know when you are referencing a table name.


don't rely on intellisense to tell you what's correct. a table named State is fine. But when in doubt, surround in [], like [State].


Most of our tables follow a slightly different naming scheme.

For example, instead of "State" which indicates a single item we call it "States". Instead of "Advertiser" (same thing) we use "Advertisers"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜