![]() Sometimes you may need to drop any table before creating any new table so that name collision does not take place. To delete an entity you have to execute the as followings:ĭeleteSql = " DELETE FROM Artists WHERE ID = '1' " ![]() UpdateSql = " UPDATE Artists SET NAME= 'Tauwang' WHERE ID = '1' " To update any attribute of any entity do the following: Suppose, you want to rename the name of the first artist from Towang to Tauwang. Retrive = "Select * from Artists " #executing the quires To do this have a look at the following example: We have inserted two rows in the above code. #commiting the connection then closing it. Insert2 = "INSERT INTO Artists(NAME, TRACK) VALUES('Sadduz', 'Rock' ) " #executing the quires Insert1 = "INSERT INTO Artists(NAME, TRACK) VALUES('Towang', 'Jazz' ) " First you have to write the queries to insert different data, then execute it with the help of cursor. Now our interest is to insert some row entities in the table. import pymysqlĬonnection = nnect(host= "localhost", user= "root", passwd= "", database= "databaseName")ĪrtistTableSql = """CREATE TABLE Artists(Ī table named Artists will be created. Let’s now create a table named Artist having columns – name, id and track. Using this connection we have created a cursor that will be used for different queries. localhost, and the rest three are as they are declared. # some other statements with the help of cursorįirst we have imported the pymysql, then established a connection. The following will connect to mysql database in python program.Ĭonnection = nnect(host= "localhost",user= "root",passwd= "",database= "databaseName" ) From browser ( I have created a database named databaseName which is shown below:įirst we have to build connection with the mysql. ![]() Before starting coding run the xampp control panel and start Apache & MySQL.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |