コード例 #1
0
        public void AddColumn(Table table, Attribute attribute)
        {
            conn.Open();

            SqlCommand command = new SqlCommand(" ");

            command.Connection  = conn;
            command.CommandText = "ALTER TABLE " + table.Name +
                                  " ADD " + attribute.Name +
                                  " " + attribute.Type + " ";

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

            command.CommandText += " ";

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

            command.CommandText += "; ";



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


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

            context.AttributeSet.Add(attribute);
            context.SaveChanges();
        }
コード例 #2
0
        public void SelectDatabase(Database database)
        {
            conn.Open();

            SqlCommand command = new SqlCommand(" ");

            command.Connection = conn;
            ///TODO: доделать запросы
            //CREATE TABLE TableName (TableNameId int IDENTITY(1,1) PRIMARY KEY);
            command.CommandText = "USE " + database.Name + ";";

            command.Connection = conn;
            command.ExecuteNonQuery();
            conn.Close();
            context.SaveChanges();
        }