使用SQlite在Python shell中获取自动ID

使用SQlite在Python shell中获取自动ID,python,sqlite,Python,Sqlite,当用户输入其他信息时,我需要帮助为员工创建自动ID,是否有人能提供帮助?我不希望用户要求输入员工ID,我希望它自动生成并输入到该字段中。我还必须用python编程,我不能使用SQL程序或任何东西。请随意更改代码的任何部分,目前它非常脆弱,我一直在与“rowid”代码混在一起,试图让它正常工作,但我无法理解,非常感谢 import sqlite3 def AddEmployee(): FirstName = input("Plaese enter the

当用户输入其他信息时,我需要帮助为员工创建自动ID,是否有人能提供帮助?我不希望用户要求输入员工ID,我希望它自动生成并输入到该字段中。我还必须用python编程,我不能使用SQL程序或任何东西。请随意更改代码的任何部分,目前它非常脆弱,我一直在与“rowid”代码混在一起,试图让它正常工作,但我无法理解,非常感谢

import sqlite3


def AddEmployee():
    FirstName = input("Plaese enter the
                      employee's First Name: ")
    LastName = input("Please enter the
                     employee's Last Name: ")
    DName = input("Please Enter the employee's
                  Department Area: ")
    Gender = input("Please enter the employee's
                   Gender: ")
    Phone = int(input("Please enter the
                      employee's phone number: "))
    Address1 = input("Please Enter the
                     employee's Address1: ")
    Town = input("Please Enter the employee's
                 Town: ")
    Postcode = input("Please Enter the
                     employee's Postcode: ")
    DOB = input("Please Enter the employee's
                Date of Birth: ")
    HireDate = input("Please Enter the
                     employee's Date of Employment: ")

    db = sqlite3.connect("Database.db")
    cursor = db.cursor()
    cursor.execute("INSERT INTO Employees
                   VALUES(rowid, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                   (EmployeeID, FirstName, LastName, DName,
                       Gender, Phone, Address1, Town, Postcode,
                       DOB, HireDate))
    db.commit()
    cursor.close()


db = sqlite3.connect("Database.db")
cursor = db.cursor()
cursor.execute("""CREATE TABLE IF NOT 
EXISTS Employees
(EmployeeID integer PRIMARY KEY 
AUTOINCREMENT, DName integer,
FirstName text, LastName text, Gender text,                 
Phone text,
Address1 text, Town text, Postcode text,         
DOB Date,
HireDate Date)""")

cursor.execute("""CREATE TABLE IF NOT     
EXISTS Salaries
(SalaryID integer PRIMARY KEY 
AUTOINCREMENT, EmployeeID integer,
DepartmentDI integer, RegisterID integer,     
FirstName text,
LastName text, Address1 text, Town text, 
Postcode text, DOB Date,
HireDate Date, SalaryAmount integer, 
DhourlyRate integer,
DOvertimeHourlyRate integer)""")

cursor.execute("""CREATE TABLE IF NOT 
EXISTS Register
(RegisterID integer PRIMARY KEY 
AUTOINCREMENT, EmployeeID integer,
Date Date, Time Time, Present Boolean, 
HoursWorked integer,
OvertimeWorked integer)""")

cursor.execute("""CREATE TABLE IF NOT 
EXISTS Departments
(DepartmentID integer PRIMARY KEY 
AUTOINCREMENT, DName text, DQuota integer,
DHourlyRate integer, DovertimeHourlyRate 
integer)""")

db.commit()
cursor.close()
AddEmployee()
你可以这样做

id = odm.SymbolField(primary_key=True)
如果没有主键字段,python会自动创建它。

您可以这样做

id = odm.SymbolField(primary_key=True)

如果没有包含主键的字段,python会自动创建它。

您希望如何获得员工id?它应该是随机的吗?还是按顺序?要求是什么?请查看问题可能重复的如果在要插入的
列中未包含
整数主键
列,则会自动为其分配一个数字。查看您希望员工id如何显示?它应该是随机的吗?还是按顺序?要求是什么?请查看问题可能重复的如果在要插入的
列中未包含
整数主键
列,则会自动为其分配一个数字。看见