I have a java swing application that interacts with MySQL and i want to be able to create license key that allow the user to use the application, the user can only have one license number, here is what i have so far in SQL.
CREATE TABLE User (
id INT AUTO_INCREMENT NOT NULL,
License VARCHAR(100) NOT NULL,
PRIMARY KEY(id)
);
CREATE TABLE Address (
id INT AUTO_INCREMENT NOT NULL,
LicenseNumber VARCHAR(255) NOT NULL,
FOREIGN KEY (LicenseNumber) REFERENCES User(id),
PRIMARY KEY(id)
);
Is this the correct solution? also what would be a good way to generate the actual License Number with SQL?
This is my solution to my question: Here is the SQL:
CREATE TABLE User(
id int NOT NULL auto_increment primary key,
LicenseID VARCHAR(100) NULL,
CONSTRAINT fk_license_number FOREIGN KEY (LicenseID) REFERENCES License(LicenseNumber)
);
CREATE TABLE License(
id INT AUTO_INCREMENT NOT NULL,
LicenseNumber VARCHAR(100) NOT NULL UNIQUE,
PRIMARY KEY (ID)
);
For the LicenseNumber, i went ahead and used sha1 in my java code Java String to SHA1