jueves, marzo 23, 2023
InicioSoftware EngineeringEasy methods to Create a Major Key for a MySQL Database in...

Easy methods to Create a Major Key for a MySQL Database in Python


You possibly can create a Major Key in your MySQL database in Python as follows.

First, it’s essential know if the Major Key already exists.

Choice 1 – The Major Key doesn’t Exist

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  consumer = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE TABLE clients (id INT AUTO_INCREMENT PRIMARY KEY, identify VARCHAR(255), tackle VARCHAR(255))")

Choice 2 – The Major Key already Exists

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  consumer = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()

mycursor.execute("ALTER TABLE clients ADD COLUMN id INT AUTO_INCREMENT PRIMARY KEY")
admin
adminhttps://shortsavepeli.xyz
Lover of movies and series. rather. lover to the cinema in generating. I hope you like my blog.
RELATED ARTICLES

DEJA UNA RESPUESTA

Por favor ingrese su comentario!
Por favor ingrese su nombre aquí

Most Popular

Recent Comments