Autor Beitrag
pepe-je
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: So 11.04.10 15:14 
Hallo,
bei der Bildung einer neuen Tabelle soll die Id mit Auto_Increment versehen sein. Ich habe versucht, dies mit folgender Zeile zu erreichen

String strComm = "CREATE TABLE Staedte (Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, ...)";
cmd = new SqlCommand(cmdStr, conn);

Der Befehl CREATE TABLE ... wird dann mit
cmd.ExecuteNonQuery();
an die Datenbank übergeben

Leider gibt es die Meldung eines syntaktischen Fehlers für AUTO_INCREMENT
Kann mir jemand helfen? Danke

Gruß, pepe-je
Raorkon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 86
Erhaltene Danke: 1



BeitragVerfasst: So 11.04.10 15:39 
mhh versuchs mal so:

ausblenden Quelltext
1:
CREATE TABLE [dbo].[BlaTable]([ID] [int] IDENTITY(1,1) NOT NULL,.......)					
JüTho
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2021
Erhaltene Danke: 6

Win XP Prof
C# 2.0 (#D für NET 2.0, dazu Firebird); früher Delphi 5 und Delphi 2005 Pro
BeitragVerfasst: So 11.04.10 16:42 
Hallo,

die DBMS sind bei der Struktur der Befehle sehr empfindlich. Vermutlich muss das Auto_increment vor dem PrimaryKey stehen.

Gruß Jürgen
pepe-je Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: So 11.04.10 17:40 
--Leider bringt die Vertauschung von PRIMARY KEY und AUTO_INCREMENT keine Veränderung. Wieder kommt die Meldung: "Syntaxfehler in Umgebung von AUTO_INCREMENT.

Wird AUTO_INCREMENT durch IDENTITY (1,1) ersetzt, wird die Tabelle richtig angelegt.
Aber erfolgt denn nun eine automatische Erhöhung der Id?
Raorkon
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 86
Erhaltene Danke: 1



BeitragVerfasst: So 11.04.10 17:43 
ja macht er, du nutzt also wahrscheinlich MS SQL 2005/2008
pepe-je Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 23



BeitragVerfasst: So 11.04.10 18:25 
Euch beiden vielen Dank für Eure Hilfe
Viele Grüße. Peter
Christoph1972
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 690
Erhaltene Danke: 16


VS2015 Pro / C# & VB.Net
BeitragVerfasst: So 11.04.10 21:09 
By the way, bei mir sieht das so aus: ID INT PRIMARY KEY NOT NULL IDENTITY

Auto Increment scheint dann default zu sein......SQL-Server 2005

_________________
Gruß
Christoph