--File Version: 1.0.0.0 for SQL Server --Purpose: Creates an empty database template in SQL for the Advertising Profit Control software; master template. --Notes: This version does not implement any table relationships, its just flat data tables. -- Currency will be represented with DECIMAL(19,2) as the standard. From stackoverflow: -- http://stackoverflow.com/questions/628637/best-data-type-for-storing-currency-values-in-a-mysql-database --Create the database called "AdvertisingProfitControl". CREATE DATABASE AdvertisingProfitControl --Begin creating the tables for the database. CREATE TABLE ActualSales ( Id INTEGER NOT NULL PRIMARY KEY, --Sold and sale price need to be stored as a string since they need to support # Bin(s) --and $#.##/# formatting respectively. Sold VARCHAR(128), SalePrice VARCHAR(128), --Might be over kill to store money like this but better safe then sorry. TotalSales DECIMAL(19,2), Cost DECIMAL(19,2), ProfitReturn DECIMAL(19,2), TotalProfitReturn DECIMAL(19,2), --The attributes of the row can not be null, and neither can the foreign keys. RowPosition INTEGER NOT NULL, --A precision of two digits should be everything we need for the row attribute. RowAttribute INTEGER NOT NULL, --Now begin all the foreign keys. FkAdItemId INTEGER NOT NULL, FkAdSpecialGoupId INTEGER NOT NULL, FkDateId INTEGER NOT NULL ) CREATE TABLE AdItem ( Id INTEGER NOT NULL PRIMARY KEY, AdItem VARCHAR(255) NOT NULL, Description VARCHAR(255) --Optional field may be used later one. ) CREATE TABLE AdSpecial ( Id INTEGER NOT NULL PRIMARY KEY, AdSpecial VARCHAR(255) NOT NULL, Description VARCHAR(255) --Optional field may be used later one, most likely in a tool tip. ) CREATE TABLE Note --Comment is a reserved word so the table and column had to be renamed to "Note" instead. ( Id INTEGER NOT NULL PRIMARY KEY, --The current version (1.0.0.0) only allows the user to enter a max of 256 characters into the comments box. Note VARCHAR(256) NOT NULL, FkDateId INTEGER NOT NULL ) CREATE TABLE CostAnalysis ( Id INTEGER NOT NULL PRIMARY KEY, SalesPerManHour DECIMAL(19,2), --Allows percentages between %1000.00 (10,000 percent) and %0.12356. SalaryPercentage DECIMAL(6,2), --The percentage of the manager's salary that was made on this week's sale items. SalaryDollar DECIMAL(19,2), -- Supplies DECIMAL(19,2) --Total of costs from invoices (?). ) CREATE TABLE Holiday ( Id INTEGER NOT NULL PRIMARY KEY, Holiday VARCHAR(64) NOT NULL ) CREATE TABLE Inventory ( Id INTEGER NOT NULL PRIMARY KEY, --All values minus the primary key and foreign keys are set as strings to allow --specifying the number of bins of product are present. BeginningInventory VARCHAR(255), Recieved VARCHAR(255), TotalInventory VARCHAR(255), EndingInventory VARCHAR(255), --The attributes of the row can not be null, and neither can the foreign keys. RowPosition INTEGER NOT NULL, --A precision of two digits should be everything we need for the row attribute. RowAttribute INTEGER NOT NULL, --Now begin all the foreign keys. FkAdItemId INTEGER NOT NULL, FkAdSpecialGoupId INTEGER NOT NULL, FkDateId INTEGER NOT NULL ) CREATE TABLE Invoice ( Id INTEGER NOT NULL PRIMARY KEY, InvoiceDate DATE NOT NULL, InvoiceNumber INTEGER NOT NULL, InvoiceNetAmountAtCost DECIMAL(19,2), InvoiceNetAmount DECIMAL(19,2), InvoiceNote VARCHAR(255), --Keys are never allowed to be null. FkSupplierId INTEGER NOT NULL, FkDateId INTEGER NOT NULL ) CREATE TABLE Projections ( Id INTEGER NOT NULL PRIMARY KEY, --Sold and sale price need to be stored as a string since they need to support # Bin(s) --and $#.##/# formatting respectively. Sold VARCHAR(128), SalePrice VARCHAR(128), --Might be over kill to store money like this but better safe then sorry. TotalSales DECIMAL(19,2), Cost DECIMAL(19,2), ProfitReturn DECIMAL(19,2), TotalProfitReturn DECIMAL(19,2), --The attributes of the row can not be null, and neither can the foreign keys. RowPosition INTEGER NOT NULL, --A precision of two digits should be everything we need for the row attribute. RowAttribute INTEGER NOT NULL, --Now begin all the foreign keys. FkAdItemId INTEGER NOT NULL, FkAdSpecialGoupId INTEGER NOT NULL, FkDateId INTEGER NOT NULL ) CREATE TABLE Supplier ( Id INTEGER NOT NULL PRIMARY KEY, Supplier VARCHAR(255), Description VARCHAR(255) --Optional field may be used later one. ) CREATE TABLE Taxable ( Id INTEGER NOT NULL PRIMARY KEY, Sunday DECIMAL(19,2), Monday DECIMAL(19,2), Tuesday DECIMAL(19,2), Wednesday DECIMAL(19,2), Thursday DECIMAL(19,2), Friday DECIMAL(19,2), Saturday DECIMAL(19,2), Total DECIMAL(19,2), --Keys are never allowed to be null. FkDateId INTEGER NOT NULL ) CREATE TABLE Version ( Id INTEGER NOT NULL PRIMARY KEY, VersionNumber VARCHAR(64) --64 characters should be more then enough to store a version number. ) CREATE TABLE WeekEndingDate ( Id INTEGER NOT NULL PRIMARY KEY, WeekEndingDate DATE NOT NULL --A date is required to be entered. ) CREATE TABLE WeeklySales ( Id INTEGER NOT NULL PRIMARY KEY, Sunday DECIMAL(19,2), Monday DECIMAL(19,2), Tuesday DECIMAL(19,2), Wednesday DECIMAL(19,2), Thursday DECIMAL(19,2), Friday DECIMAL(19,2), Saturday DECIMAL(19,2), TotalSales DECIMAL(19,2), --Keys are never allowed to be null. FkDateId INTEGER NOT NULL )