-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate.py
More file actions
39 lines (24 loc) · 870 Bytes
/
Copy pathcreate.py
File metadata and controls
39 lines (24 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="",database="mydatabase")
A=mydb.cursor()
# for creating a new database.
A.execute("CREATE DATABASE mydatabase")
# for checking all database's
A.execute("SHOW DATABASES")
for i in A:
print(i)
# for creating a table in database. create table must be in capitale letters
A.execute("CREATE TABLE ba( Sid int(5), name varchar(255), rollno int(11), result varchar(4))")
# for adding primary key in a coloum
A.execute("CREATE TABLE bcom( id int AUTO_INCREMENT PRIMARY KEY, name varchar(255), rollno int(11), result varchar(4))")
#for checking tables exixting.
A.execute("show tables")
print("\n\n")
for i in A:
print(i)
A.execute("ALTER TABLE ba add column marks int(3)")
#for fetch data from a table
A.execute('select name from ba')
B=A.fetchall()
for i in B:
print(i)