Create Table - Time Statement

173 views Asked by At

I am having trouble trying to create a table using MS Access.

I know for sure my problem lies in the "datetime" field but I can not figure what I am missing or doing wrong.

When I click "run" I get the

"Syntax Error in Field Definition"

Create Table Appointments
(DocID             char(4)             not null       primary key,
 PatID             char(8)             not null,      
 Day               varchar(8)          not null,      
 Time              datetime            not null,
 Procedure         varchar(50)         null);
3

There are 3 answers

1
Mureinik On BEST ANSWER

Time and procedure are reserved words, and therefore should be escaped:

Create Table Appointments
(DocID             char(4)             not null       primary key,
 PatID             char(8)             not null,      
 [Day]             varchar(8)          not null,      
 [Time]            datetime            not null,
 [Procedure]       varchar(50)         null); 

Or better yet, find names that aren't reserved words:

Create Table Appointments
(DocID             char(4)             not null       primary key,
 PatID             char(8)             not null,      
 AppointmentDay    varchar(8)          not null,      
 AppointmentTime   datetime            not null,
 MedicalProcedure  varchar(50)         null);
0
HaveNoDisplayName On

As Time & Procedure are reserved keyword, so wrap Time & Procedure column in brackets [] or choose alternate names, if possible. See List of Keyword

[Time] and [Procedure]
0
Rahul On

Here Procedure and Time are reserved words and so need to be escaped using [] like below. See Documentation for more information

Create Table Appointments
(DocID             char(4)             not null       primary key,
 PatID             char(8)             not null,      
 [Day]               varchar(8)          not null,      
 [Time]              datetime            not null,
 [Procedure]         varchar(50)         null);