Beispiel #1
0
        private void RenameColumn(Table table, Column column, string renameFrom, Queue<SchemaItem> callbackQueue)
        {
            log("Renaming Column: " + renameFrom + " -> " + column.Name);

            ExecuteNonQuery("EXEC sp_rename @p1, @p2, 'COLUMN';",
                table.Name + "." + renameFrom,
                column.Name);
        }
Beispiel #2
0
        private void CreateColumn(Table table, Column column, Queue<SchemaItem> callbackQueue)
        {
            log("Creating Column: " + column.Name);
            RunCallback(column, CallbackAction.Before);
            callbackQueue.Enqueue(column);
            string typeDesc = GetColumnDescriptor(column);

            string query = string.Format("ALTER TABLE [{0}] ADD [{1}] {2}", table.Name, column.Name, typeDesc);
            ExecuteNonQuery(query);
        }
Beispiel #3
0
        private void CreateForeignKey(Table table, Column column)
        {
            string keyname = string.Format("FK_{0}_{1}_{2}", table.Name, column.Name, column.References);
            List<string> fkeys = existingForeignKeys.GetValueOrDefault(table.Name.Trim());
            if (Exists(fkeys, keyname))
                return;

            log("Creating Foreign Key: " + keyname);

            existingForeignKeys.GetValue(table.Name, () => new List<string>()).Add(keyname);
            finalUpdates.Add(string.Format("ALTER TABLE [{0}] ADD CONSTRAINT [FK_{0}_{1}_{2}] FOREIGN KEY ([{1}]) REFERENCES [{2}];", table.Name, column.Name, column.References));
        }
Beispiel #4
0
        private static string GetColumnDescriptor(Column column)
        {
            string typeDesc = GetTypeDescriptor(column);

            if (!column.Nullable)
                typeDesc += " NOT NULL";
            if (!string.IsNullOrEmpty(column.DefaultValue))
                typeDesc += " DEFAULT (" + column.DefaultValue + ")";

            bool identity;
            if (Boolean.TryParse(column.IsIdentity, out identity) && identity)
                typeDesc += " IDENTITY";
            return typeDesc;
        }