|
Farg’ona Politexnika Instituti tjbakt yo’nalishi 52-21 guruh talabasining fizika fanidan tayyorlagan taqdimot loyihasi
|
bet | 3/3 | Sana | 10.01.2024 | Hajmi | 499,92 Kb. | | #133727 |
Bog'liq maxmudova nMisol: EMPLOYEE ma'lumotlar bazasi jadvalini yarataylik - #!/usr/bin/python3 import pymysql # Open database connection db = pymysql.connect("localhost","testuser","test123","TESTDB" ) # prepare a cursor object using cursor() method cursor = db.cursor() # Drop table if it already exist using execute() method. cursor.execute("DROP TABLE IF EXISTS EMPLOYEE") # Create table as per requirement sql = """CREATE TABLE EMPLOYEE ( FIRST_NAME CHAR(20) NOT NULL, LAST_NAME CHAR(20), AGE INT, SEX CHAR(1), INCOME FLOAT )""" cursor.execute(sql) # disconnect from server db.close() Ma'lumotlar bazasi jadvalida yozuvlaringizni yaratmoqchi bo'lganingizda INSERT operatsiyasi talab qilinadi. Quyidagi misol, EMPLOYEE jadvalida yozuv yaratish uchun SQL INSERT operatorini bajaradi - #!/usr/bin/python3 import pymysql # Open database connection db = pymysql.connect("localhost","testuser","test123","TESTDB" ) # prepare a cursor object using cursor() method cursor = db.cursor() # Prepare SQL query to INSERT a record into the database. sql = """INSERT INTO EMPLOYEE(FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUES ('Mac', 'Mohan', 20, 'M', 2000)""" try: # Execute the SQL command cursor.execute(sql) # Commit your changes in the database db.commit() except: # Rollback in case there is any error db.rollback() # disconnect from server db.close()
|
|
Bosh sahifa
Aloqalar
Bosh sahifa
Farg’ona Politexnika Instituti tjbakt yo’nalishi 52-21 guruh talabasining fizika fanidan tayyorlagan taqdimot loyihasi
|