Creating a table - Python
Užbaigimo reikalavimai
Creating a table
A database is a collection of tables with a specific structure where the data is stored. After the connection with the database is established, let’s create our first table:
cursor.execute("CREATE TABLE customers ("
"(firstName VARCHAR(255),"
"lastName VARCHAR(255),”
“entryID INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(entryID)); )")
cnxn.commit() # this commits changes to the database<span style="font-size: 15px; white-space: normal;">
</span>
The table customers is now created with the following characteristics:
- The first field (column) named firstName formatted to accept 255 alphanumerics (VARCHAR) characters.
- The second field (column) named lastName formatted to accept 255 alphanumerics (VARCHAR) characters.
- The third field (column) named entryID formatted to accept an integer number (INT), mandatory (NOT NULL), filled with an incremental number (AUTO_INCREMENT), and defined as an index field (PRIMARY KEY).