4 Replies - 908 Views - Last Post: 30 July 2011 - 02:30 PM Rate Topic: -----

#1 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Error when trying to create two tables in my SQL Compact database.

Posted 30 July 2011 - 06:49 AM

First time using this database because I need a type that's portable and so far it's been a headache. I can't seem to figure out what's wrong with the code.

Here's what I'm trying to run - it's in Spanish but you get the gist of it:

create table UsuarioRol
(
UsuarioRolId int primary key identity(1,1),
Nombre nvarchar(64) not null,
NivelAutoridad int not null
)

create table Usuario
(
UsuarioId int primary key identity(1,1),,
UsuarioRolId int foreign key references UsuarioRol(UsuarioRolId),
Login nvarchar(64) not null,
Password nvarchar(64) not null
)


I get the error:

Quote

---------------------------
Microsoft Visual Studio
---------------------------
SQL Execution Error.

Executed SQL statement: create table UsuarioRol

(

UsuarioRolId int primary key identity(1,1),

Nombre nvarchar(64) not null,

NivelAutoridad int not null

)



create table Usuario

(

UsuarioId int primary key identity(1,1),,

UsuarioRolId int foreign key references Usua...
Error Source: SQL Server Compact ADO.NET Data Provider
Error Message: There was an error parsing the query. [ Token line number = 8,Token line offset = 1,Token in error = create ]
---------------------------
OK Help
---------------------------


I don't understand what might be wrong in the syntax. Am I missing something here?

Thanks for the help! :)

Edit: Even tried this, and I get the same error.

create table [UserRole]
(
UserRoleId int primary key identity(1,1),
Name nvarchar(64) not null,
Authority int not null
)

create table [User]
(
UserId int primary key identity(1,1),
Username nvarchar(32) not null,
Password nvarchar(64) not null,
UserRoleId int foreign key references UserRole(UserRoleId)
)


This post has been edited by Sergio Tapia: 30 July 2011 - 06:53 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Error when trying to create two tables in my SQL Compact database.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Error when trying to create two tables in my SQL Compact database.

Posted 30 July 2011 - 06:52 AM

UsuarioId int primary key identity(1,1),,


Two commas?
Was This Post Helpful? 1
  • +
  • -

#3 Sergio Tapia  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1253
  • View blog
  • Posts: 4,168
  • Joined: 27-January 10

Re: Error when trying to create two tables in my SQL Compact database.

Posted 30 July 2011 - 06:55 AM

Yeah missed that completely. I wish SQL had some sort of syntax checker built in Visual Studio.

Still the error persists. It says it's on line 8 and I can't see anything wrong with that line.

Edit: Running the exact same TSQL (removing the extra comma you mentioned) on a regular ol' SQL Server database, runs perfectly.

create table UsuarioRol
(
UsuarioRolId int primary key identity(1,1),
Nombre nvarchar(64) not null,
NivelAutoridad int not null
)

create table Usuario
(
UsuarioId int primary key identity(1,1),
UsuarioRolId int foreign key references UsuarioRol(UsuarioRolId),
Login nvarchar(64) not null,
Password nvarchar(64) not null
)



Can I conclude that SQL Compact doesn't support foreign keys?

This post has been edited by Sergio Tapia: 30 July 2011 - 06:58 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Error when trying to create two tables in my SQL Compact database.

Posted 30 July 2011 - 08:55 AM

Is a semi-colon required after the table definition perhaps? I don't use MSSQL very often.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: Error when trying to create two tables in my SQL Compact database.

Posted 30 July 2011 - 02:30 PM

Since the first table is required before the second table, maybe putting a GO statement between the two table creation statements so the first will be executed before the second one.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1