# File src/rails-1.0.0/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb, line 169 def add_index(table_name, column_name, options = {}) index_name = "#{table_name}_#{Array(column_name).first}_index" if Hash === options # legacy support, since this param was a string index_type = options[:unique] ? "UNIQUE" : "" index_name = options[:name] || index_name else index_type = options end execute "CREATE #{index_type} INDEX #{index_name} ON #{table_name} (#{Array(column_name).join(", ")})" end
Adds a new index to the table. column_name can be a single Symbol, or an Array of Symbols.
The index will be named after the table and the first column names, unless you pass +:name+ as an option.
Examples
Creating a simple index
generates
Creating a unique index
generates
Creating a named index
generates