Example #1
0
        public void EditDatabase(Database database, string name)
        {
            conn.Open();

            SqlCommand command = new SqlCommand(" ");

            command.Connection = conn;
            command.Connection = conn;
            //sp_rename 'supplier', 'vendor';
            command.CommandText = "sp_renamedb '" + database.Name + "', '" + name + "';";

            database.Name = name;

            command.ExecuteNonQuery();
            conn.Close();
            context.Entry(context.TableSet.Find(database.Id)).CurrentValues.SetValues(database);
            context.SaveChanges();
        }
Example #2
0
        public void EditColumn(Table table, Attribute oldAttribute, Attribute newAttribute)
        {
            conn.Open();

            SqlCommand command = new SqlCommand(" ");

            command.Connection = conn;

            command.CommandText = "sp_rename" +
                                  "'" + table.Name + "." + oldAttribute.Name + "'," +
                                  "'" + newAttribute.Name + "', 'COLUMN; " +
                                  "GO";

            command.CommandText += "ALTER TABLE " + table.Name +
                                   " ALTER COLUMN " + newAttribute.Name + " " + newAttribute.Type;

            if (newAttribute.Length != 0)
            {
                command.CommandText += "(" + newAttribute.Length.ToString() + ")";
            }

            command.CommandText += " ";

            if (!newAttribute.IsNull)
            {
                command.CommandText += "NOT NULL";
            }

            command.CommandText += "; ";

            if (newAttribute.Indexed)
            {
                command.CommandText += "CREATE INDEX " + "idx_" + table.Name + "_" + newAttribute.Name +
                                       " ON " + table.Name + "(" + newAttribute.Name + "); ";
            }


            command.ExecuteNonQuery();
            conn.Close();

            context.Entry(oldAttribute).CurrentValues.SetValues(newAttribute);
            context.SaveChanges();
        }