package main
import (
"database/sql"
"fmt"
"log"
)
func main() {
// Open a connection to the database
db, err := sql.Open("mysql", "user:password@tcp(127.0.0.1:3306)/dbname")
if err != nil {
log.Fatal(err)
}
defer db.Close()
// Prepare the SQL statement to alter the unique key
stmt, err := db.Prepare("ALTER TABLE your_table DROP INDEX your_index, ADD UNIQUE KEY your_new_unique_key (column1, column2)")
if err != nil {
log.Fatal(err)
}
// Execute the SQL statement
_, err = stmt.Exec()
if err != nil {
log.Fatal(err)
}
fmt.Println("Unique key altered successfully")
}