Szukam info na temat w jaki sposob moge stworzyć Tabele w bazie danych sql z poziomu kodu?
Prosił bym o jakis przykład, bądź link. Znalazłem w necie takie coś, ale mi to amło mówi bo nie ma namespaców i nie wiem dokładnie skąd pochodzą używane klasy.
// Establish the database server
string connectionString = "...";
SqlConnection connection =
new SqlConnection(connectionString);
Server server =
new Server(new ServerConnection(connection));
// Create table in my personal database
Database db = server.Databases["davidhayden"];
// Create new table, called TestTable
Table newTable = new Table(db, "TestTable");
// Add "ID" Column, which will be PK
Column idColumn = new Column(newTable, "ID");
idColumn.DataType = DataType.Int;
idColumn.Nullable = false;
idColumn.Identity = true;
idColumn.IdentitySeed = 1;
idColumn.IdentityIncrement = 1;
// Add "Title" Column
Column titleColumn = new Column(newTable, "Title");
titleColumn.DataType = DataType.VarChar(50);
titleColumn.Nullable = false;
// Add Columns to Table Object
newTable.Columns.Add(idColumn);
newTable.Columns.Add(titleColumn);
// Create a PK Index for the table
Index index = new Index(newTable, "PK_TestTable");
index.IndexKeyType = IndexKeyType.DriPrimaryKey;
// The PK index will consist of 1 column, "ID"
index.IndexedColumns.Add(new IndexedColumn(index,"ID"));
// Add the new index to the table.
newTable.Indexes.Add(index);
// Physically create the table in the database
newTable.Create();