Hallo Leute,
ich versuche eine kleine Datenbank aufzusetzen um Betriebsdaten von Geräten katalogisiert zu speichern . Ich bin aber ein absoluter neuling. und habe ein Problem mit dem Foreign-Key.
mein sqript sieht so aus:
create table registration_tab
(
registrationID bigint not null,
clockstamp smalldatetime,
deviceID smallint,
Primary Key (registrationID)
foreign key (deviceID) references device_tab(deviceID
)
create table device_tab
(
deviceID smallint not null,
serialnumber bigint,
devicetypeID smallint,
Primary Key (devivceID)
foreign key (devicetypeID) references devicetype_tab(devtypeID)
)
create table devicetype_tab
(
devicetypeID smallint not null,
wrdescription text,
Primary Key (devicetypeID)
)
create table channellist_tab
(
channelID int,
devicetypeID smallint,
Primary Key (channelID, devicetypeID)
foreign key (channelID) references channel_tab(channelID)
foreign key (devicetypeID) references devicetype_tab(devicetypeID)
)
create table channel_tab
(
channelID int not null,
channelname text,
unit text,
multi smallint,
Primary Key (channelID)
)
create table regvalue_tab
(
registrationvalueID bigint not null,
value bigint,
registrationID bigint,
channelID int,
Primary Key (registrationvalueID)
foreign key (registrationID) references registration_tab(registrationID)
foreign key (channelID) references channel_tab(ChannelID)
)
und das Ergebnisfenster haut immer diesen Fehler raus:
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 11
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 23
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 43
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 69
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Was mache ich da falsch?
Ich habe die FK-Syntax aus einem O´Reilly-Buch.
Kann mir da einer von euch helfen.Bitte nicht rüffeln, aber ich bin wirklich newest newbie.
Würde mich über eine Antwort freuen. Vielleicht kann mir ja auch einer die Syntax mal kurz erklärem
Danke.
LG
Kasu
ich versuche eine kleine Datenbank aufzusetzen um Betriebsdaten von Geräten katalogisiert zu speichern . Ich bin aber ein absoluter neuling. und habe ein Problem mit dem Foreign-Key.
mein sqript sieht so aus:
create table registration_tab
(
registrationID bigint not null,
clockstamp smalldatetime,
deviceID smallint,
Primary Key (registrationID)
foreign key (deviceID) references device_tab(deviceID
)
create table device_tab
(
deviceID smallint not null,
serialnumber bigint,
devicetypeID smallint,
Primary Key (devivceID)
foreign key (devicetypeID) references devicetype_tab(devtypeID)
)
create table devicetype_tab
(
devicetypeID smallint not null,
wrdescription text,
Primary Key (devicetypeID)
)
create table channellist_tab
(
channelID int,
devicetypeID smallint,
Primary Key (channelID, devicetypeID)
foreign key (channelID) references channel_tab(channelID)
foreign key (devicetypeID) references devicetype_tab(devicetypeID)
)
create table channel_tab
(
channelID int not null,
channelname text,
unit text,
multi smallint,
Primary Key (channelID)
)
create table regvalue_tab
(
registrationvalueID bigint not null,
value bigint,
registrationID bigint,
channelID int,
Primary Key (registrationvalueID)
foreign key (registrationID) references registration_tab(registrationID)
foreign key (channelID) references channel_tab(ChannelID)
)
und das Ergebnisfenster haut immer diesen Fehler raus:
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 11
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 23
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 43
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Server: Nachr.-Nr. 156, Schweregrad 15, Status 1, Zeile 69
Falsche Syntax in der Nähe des foreign-Schlüsselwortes.
Was mache ich da falsch?
Ich habe die FK-Syntax aus einem O´Reilly-Buch.
Kann mir da einer von euch helfen.Bitte nicht rüffeln, aber ich bin wirklich newest newbie.
Würde mich über eine Antwort freuen. Vielleicht kann mir ja auch einer die Syntax mal kurz erklärem
Danke.
LG
Kasu
Comment