public void WithUniqueConstraintOn(string column, string name)
        {
            var sb = new StringBuilder();

            sb.Append(string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE ({2})", _quoter.QuoteTableName(Name), _quoter.QuoteConstraintName(name), _quoter.QuoteColumnName(column)));
            _processor.Execute(sb.ToString());
            _constraints.Add(name);
        }
Example #2
0
        public void WithUniqueConstraintOn(string column, string name)
        {
            var constraintName = _quoter.QuoteConstraintName(name, _schema);

            var query = string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE ({2})",
                                      NameWithSchema,
                                      constraintName,
                                      _quoter.QuoteColumnName(column)
                                      );

            Processor.Execute(query);
        }
        public void WithUniqueConstraintOn(string column, string name)
        {
            var constraintName = quoter.QuoteConstraintName(name, _schema);

            var query = string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE ({2})",
                                      NameWithSchema,
                                      constraintName,
                                      quoter.QuoteColumnName(column)
                                      );

            using (var command = Factory.CreateCommand(query, Connection, Transaction, Processor.Options))
            {
                command.ExecuteNonQuery();
            }
        }
        public string Generate(CreateConstraintExpression expression)
        {
            var constraintType = (expression.Constraint.IsPrimaryKeyConstraint) ? "PRIMARY KEY" : "UNIQUE";

            var columns = new string[expression.Constraint.Columns.Count];

            for (var i = 0; i < expression.Constraint.Columns.Count; i++)
            {
                columns[i] = Quoter.QuoteColumnName(expression.Constraint.Columns.ElementAt(i));
            }

            return(string.Format(CreateConstraintSqlTemplate, Quoter.QuoteTableName(expression.Constraint.TableName, expression.Constraint.SchemaName),
                                 Quoter.QuoteConstraintName(expression.Constraint.ConstraintName, expression.Constraint.SchemaName),
                                 constraintType,
                                 string.Join(", ", columns)));
        }
Example #5
0
        public void WithUniqueConstraintOn(string column, string name)
        {
            var sb = new StringBuilder();

            sb.Append(string.Format("ALTER TABLE {0} ADD CONSTRAINT {1} UNIQUE ({2})", quoter.QuoteTableName(Name), quoter.QuoteConstraintName(name), quoter.QuoteColumnName(column)));
            using (var command = Factory.CreateCommand(sb.ToString(), Connection, Transaction, Options))
                command.ExecuteNonQuery();
            constraints.Add(name);
        }