I want to create table with no columns in sqlite3. It is possible in postgres database, but not in a sqlite3 one. Is there any way to achieve this, or is it simply not supported (maybe not in sql standard?) I have checked sqlite3 CREATE TABLE
grammar and it seems, that there must be at least one column, but maybe 开发者_如何学PythonI have missed something?
Zero-column tables aren't supported in SQLite. Or in the SQL standard either.
I had this same question because I wanted a table with only the rowid field. While you may not be able to create a table without columns, you can make a table with only a rowid field as the primary key using the following code:
CREATE TABLE tablename (rowid INTEGER PRIMARY KEY) WITHOUT ROWID;
you can create table with only id column instead of creating empty table:
def create_table(DATABESE_NAME):
conn = sqlite3.connect(DATABESE_NAME)
c = conn.cursor()
c.execute(''' CREATE TABLE IF NOT EXISTS rate_table(
id INTEGER PRIMARY KEY AUTOINCREMENT) ''')
conn.commit()
conn.close()
精彩评论