2017-09-06 20:59:56
CREATE datebase < database name >
CREATE table < table name >
(< column name 1> < data type > < constraints required for the column;
< column name 2> < data type > < constraints required for this column;
.
< constraints on the table 1>,< the table constraints 2>.);
ImportPymysqldb= Pymysql.connect ("localhost","Root","hy1102","TESTDB") Cursor=db.cursor () SQL="""CREATE TABLE Shohin (shohin_id CHAR (4) NOT NULL, Shohin_mei varchar (+) NOT NULL, Shohin_bunrui varchar (+) not NUL L, Hanbai_tanka Integer, Shiire_tanka integer, Torrokubi DATE, PRIMARY KEY (shohin_id))"""cursor.execute (SQL) db.close ()
DROP table < table name >;
Drop table cannot be recovered, so be sure to pay special attention before deleting it.
ALTER table < table name > ADD < column definition >;
Import= Pymysql.connect ("localhost","root", " hy1102 ","TESTDB"==""ALTER table Shohin Add (Test VARCHAR) "" "cursor.execute (SQL) db.close ()
ALTER table < table name > DROP < column name >
Import= Pymysql.connect ("localhost","root", " hy1102 ","TESTDB"==""ALTER table Shohin drop test"" "cursor.execute (SQL)
Db.close ()
The updated statement of the table is also non-modifiable, so be sure to think clearly before changing it.
Python mysql-table creation, deletion and update