MySQL Create Table in Hindi – Python MySQL

Python MySql

MySQL Create Table in Hindi – Python MySQL – Is Post Me Ham Table Create Karne Wale Hai,And Table Ko Kaise Create Karte Hai Ye Bhi Dekhne Wale Hai |

MySQL Create Table in Hindi

Is Part Me Ham Table Ko Create Karne Wale Hai, Isse Pahle Hamne mydatabase Database Ko Create Kiya Tha, Ab Table Create Karte Hai.

Table Ko Create Karne Se Pahle Hame Connection Me HOST, USER, PASSWORD, DATABASE Ka Name Dena Hota Hai |

Ab Ham Table Create Karte Hai, Database Ko Create Karne Ke Liye CREATE TABLE Commands Ka Istemal Kiya Jata Hai |

Table Ka Name customers Rakhte Hai |

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="mydatabase"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE TABLE customers 
                 ( name VARCHAR (255),
                  address VARCHAR (255))
                 ")

Aap Dekh Sakte Hai ki, Hamne customers Name Se Table Ko Create Kiya Hai Or Uske Ander Hamne (name and address varchar 255) Yani ki name diya Hai Or Varchar Ka Matlab Hota Hai String And 255 Ka Matlab Hota Hai Size..

Check if Table Exists

Agar Aapko Ye Check Karna Hai Ki Aapka Pahle Koi TABLE Create Hai Ya NHi To Niche Diye Code Ko Dekh Sakte Hai Or Ye Check Kar Sakte Hai, Ki Hamara Table Pahle Create Hai, Ya Nhi |

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="mydatabase"
)

mycursor = mydb.cursor()

mycursor.execute("SHOW TABLES")

for x in mycursor:
  print(x)

Output:

('customers',)

Aap Dekh Sakte Hai, Ki Hamne upper Ek Table Create Kiya Tha, Wo Hamara Wo Output Me Print Ho Gaya Hai |

Primary Key

Primary Key Istemal Ham Har Record Ko Unique Value Dene Ke Liye Karte Hai |

INT AUTO_INCREMENT PRIMARY KEY

Or Int Auto_increment primary key Ka Matlab Hota Hai Ki ye Jis ID Ya Fir Etc.. Par Laga Diya Jaye To Auto Increment Hota Rahta Hai With Primary Key Yani Ki Unique Value Ke Sath , Iska Ham Niche Example Dekhte Hai |

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="mydatabase"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE TABLE customers 
                 (id INT AUTO_INCREMENT PRIMARY KEY,
                  name VARCHAR(255), 
                  address VARCHAR(255))")

Yah Par Hamne Fir customers Table Ko Create Kiya Or Usme Hamne id And Name Address Ko Diya Hai , ID Integer Hogi Or auto Increment Hoti Rahegi Har ek New Record Ke Sath |

Waise, Is Code Ko Hamne Understand Karne Ke Liye Dobara customers Table Ko Dikhaya Hai, Ye Hamne Database me Create Nhi Kiya Hai, Kyoki Agar Ham Ise Run Karte Hai TO YE Error Dega, Kyoki Hamne Pahle Hi customers Table Create Karli Hai |

To Ham customers Table Ko Update Karenge Or Fir id Ko Add_column Karenge |

MYSQL Update Table

Table Ko Update Karne Ke Liye Alter Commands Ka Istemal Kiya Jata Hai, Iska Niche Example Dekhte Hai |

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  password="yourpassword",
  database="mydatabase"
)

mycursor = mydb.cursor()

mycursor.execute("ALTER TABLE customers ADD COLUMN id INT AUTO_INCREMENT PRIMARY KEY")

Aap Dekhte Hai Ki Hamne customers Table Ko Uddate Kardi Hai |

Python Numpy Tutorial In Hindi

Leave a Reply

Your email address will not be published. Required fields are marked *