I know that SimpleMembership will auto create the tables needed for authentication but I would much rather run the sql scripts at some time other than when the application is ran. Is there a download page for the SimpleMembership scripts?
I found a script on github
CREATE TABLE [dbo].[UserProfile] (
[UserId] INT IDENTITY (1, 1) NOT NULL,
[UserName] NVARCHAR (MAX) NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC)
);
CREATE TABLE [dbo].[webpages_Membership] (
[UserId] INT NOT NULL,
[CreateDate] DATETIME NULL,
[ConfirmationToken] NVARCHAR (128) NULL,
[IsConfirmed] BIT DEFAULT ((0)) NULL,
[LastPasswordFailureDate] DATETIME NULL,
[PasswordFailuresSinceLastSuccess] INT DEFAULT ((0)) NOT NULL,
[Password] NVARCHAR (128) NOT NULL,
[PasswordChangedDate] DATETIME NULL,
[PasswordSalt] NVARCHAR (128) NOT NULL,
[PasswordVerificationToken] NVARCHAR (128) NULL,
[PasswordVerificationTokenExpirationDate] DATETIME NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC)
);
CREATE TABLE [dbo].[webpages_OAuthMembership] (
[Provider] NVARCHAR (30) NOT NULL,
[ProviderUserId] NVARCHAR (100) NOT NULL,
[UserId] INT NOT NULL,
PRIMARY KEY CLUSTERED ([Provider] ASC, [ProviderUserId] ASC)
);
CREATE TABLE [dbo].[webpages_Roles] (
[RoleId] INT IDENTITY (1, 1) NOT NULL,
[RoleName] NVARCHAR (256) NOT NULL,
PRIMARY KEY CLUSTERED ([RoleId] ASC),
UNIQUE NONCLUSTERED ([RoleName] ASC)
);
CREATE TABLE [dbo].[webpages_UsersInRoles] (
[UserId] INT NOT NULL,
[RoleId] INT NOT NULL,
PRIMARY KEY CLUSTERED ([UserId] ASC, [RoleId] ASC),
CONSTRAINT [fk_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[UserProfile] ([UserId]),
CONSTRAINT [fk_RoleId] FOREIGN KEY ([RoleId]) REFERENCES [dbo].[webpages_Roles] ([RoleId])
);
Related
I have some tables that will not be made when using the source command and I can't seem to find out what is wrong with them
I used MariaDB [cpt238]> source E:\database\create.sql
and got this
MariaDB [cpt238]> source E:\database\create.sql
Query OK, 0 rows affected (0.028 sec)
Query OK, 0 rows affected (0.017 sec)
Query OK, 0 rows affected (0.012 sec)
Query OK, 0 rows affected (0.013 sec)
Query OK, 0 rows affected (0.014 sec)
Query OK, 0 rows affected (0.017 sec)
Query OK, 0 rows affected (0.017 sec)
Query OK, 0 rows affected (0.023 sec)
Query OK, 0 rows affected (0.015 sec)
Query OK, 0 rows affected (0.012 sec)
Query OK, 0 rows affected (0.016 sec)
Query OK, 0 rows affected (0.016 sec)
Query OK, 0 rows affected (0.014 sec)
Query OK, 0 rows affected (0.016 sec)
Query OK, 0 rows affected (0.017 sec)
Query OK, 0 rows affected (0.007 sec)
Records: 0 Duplicates: 0 Warnings: 0
ERROR 1064 (42000) at line 122 in file: 'E:\database\create.sql': You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'create table Credential(
CRD_ID int not null auto_increment,
CRD_Title varcha...' at line 5
Query OK, 0 rows affected (0.014 sec)
Query OK, 0 rows affected (0.017 sec)
ERROR 1005 (HY000) at line 156 in file: 'E:\database\create.sql': Can't create table cpt238.student (errno: 150 "Foreign key constraint is incorrectly formed")
ERROR 1005 (HY000) at line 164 in file: 'E:\database\create.sql': Can't create table cpt238.graduation (errno: 150 "Foreign key constraint is incorrectly formed")
ERROR 1005 (HY000) at line 174 in file: 'E:\database\create.sql': Can't create table cpt238.requirement (errno: 150 "Foreign key constraint is incorrectly formed")
Query OK, 0 rows affected (0.021 sec)
Query OK, 0 rows affected (0.020 sec)
ERROR 1005 (HY000) at line 208 in file: 'E:\database\create.sql': Can't create table cpt238.fulfillment (errno: 150 "Foreign key constraint is incorrectly formed")
Query OK, 0 rows affected (0.018 sec)
This is the source file:
create table State(
Sta_Abbr char(2),
Sta_Name varchar(25) not null,
primary key (Sta_Abbr)
);
create table Zipcode(
Zip_Zipcode varchar(10) not null,
Zip_City varchar(25) not null,
Sta_Abbr char(2) not null,
primary key (Zip_Zipcode),
foreign key (Sta_Abbr) references State(Sta_Abbr)
);
create table Gender(
Gen_Gender char(1) not null,
Gen_Desc varchar(6) not null,
primary key (Gen_Gender)
);
create table Person(
Per_ID int not null auto_increment,
Per_FirstName varchar(15) not null,
Per_LastName varchar(15) not null,
Gen_Gender char(1) not null,
Per_DOB int not null,
primary key (Per_ID),
foreign key (Gen_Gender) references Gender(Gen_Gender)
);
create table ConType (
CT_ID int not null auto_increment,
CT_Desc varchar(20) not null,
primary key (CT_ID)
);
create table Phone(
Pho_ID int not null auto_increment,
Pho_Area int(3),
Pho_Exchange int(3) not null,
Pho_Extension int(4) not null,
CT_ID int not null,
primary key (pho_id),
foreign key (CT_ID) references ConType(CT_ID)
);
create table Email(
Mail_ID int not null auto_increment,
Mail_Domain varchar(10) not null,
Mail_UserName varchar(20) not null,
CT_ID int not null,
primary key (Mail_ID),
foreign key (CT_ID) references ConType(CT_ID)
);
create table Address(
Add_ID int not null auto_increment,
Sta_Abbr char(2) not null,
Zip_ZipCode varchar(15) not null,
CT_ID int not null,
primary key (Add_ID),
foreign key (Sta_Abbr) references State(Sta_Abbr),
foreign key (Zip_ZipCode) references Zipcode(Zip_Zipcode),
foreign key (CT_ID) references ConType(CT_ID)
);
create table DegType (
DT_ID int not null auto_increment,
DT_Title varchar(15) not null,
DT_Level int not null,
DT_Abbr char(4),
primary key (DT_ID)
);
create table Grade (
Grd_Sym char(2) not null,
Grd_Desc varchar(20) not null,
Grd_Credit boolean not null,
Grd_Pts int not null,
Grd_GPA boolean not null,
primary key (Grd_Sym)
);
create table Term(
Trm_Num int(2) not null,
Trm_Desc varchar(10) not null,
Trm_Length int not null,
primary key (Trm_Num)
);
create table Year(
Yr_Year int(4) not null,
primary key (Yr_Year)
);
create table Semester(
Sem_ID int not null auto_increment,
Trm_Num int(2) not null,
Yr_Year int(4) not null,
Sem_Start Date not null,
Sem_End Date not null,
primary key (Sem_ID),
foreign key (Yr_Year) references Year(Yr_Year),
foreign key (Trm_Num) references Term(Trm_Num)
);
create table Department(
Dpt_ID int not null auto_increment,
Dpt_Name varchar(35) not null,
primary key (Dpt_ID)
);
create table Faculty(
Per_ID int(4) not null,
Dpt_ID int(4) not null,
Primary key (Per_ID),
foreign key (Per_ID) references Person(Per_ID),
foreign key (Dpt_ID) references Department(Dpt_ID)
);
Alter table Department add Per_ID int not null;
Alter table Department add foreign key (Per_ID) references Faculty(Per_ID);
create table Credential(
CRD_ID int not null auto_increment,
CRD_Title varchar(25) not null,
DT_ID int not null,
CRD_Yr int(4) not null,
DPT_ID int not null,
primary key (CRD_ID),
foreign key (DT_ID) references DegType(DT_ID),
foreign key (Dpt_ID) references Department(Dpt_ID)
);
create table Subject(
Sub_Abbr char(3) not null,
Sub_Name varchar(25) not null,
DPT_ID int not null,
primary key (Sub_Abbr),
foreign key (DPT_ID) references Department(DPT_ID)
);
create table Course(
Crs_ID int not null auto_increment,
Crs_Num int(3) not null,
Sub_Abbr char(3) not null,
Crs_Desc varchar(200),
Crs_Title varchar(25) not null,
Crs_Hrs int(2) not null,
primary key (Crs_ID),
foreign key (Sub_Abbr) references Subject(Sub_Abbr)
);
create table Student(
Per_ID int not null,
CRD_ID int not null,
primary key (Per_ID),
foreign key (Per_ID) references Person(Per_ID),
foreign key (CRD_ID) references Credential(CRD_ID)
);
create table Graduation(
Grad_ID int not null auto_increment,
Per_ID int not null,
CRD_ID int not null,
Grad_Date Date not null,
primary key (Grad_ID),
foreign key (Per_ID) references Student(Per_ID),
foreign key (CRD_ID) references Credential(CRD_ID)
);
create table Requirement(
Req_ID int not null auto_increment,
CRD_ID int not null,
Crs_ID int not null,
primary key (Req_ID),
foreign key (CRD_ID) references Credential(CRD_ID),
foreign key (Crs_ID) references Course(Crs_ID)
);
create table Section(
Sec_ID int not null auto_increment,
Sec_Num int(3) not null,
Crs_ID int(3) not null,
Per_ID int not null,
Trm_Num int(2) not null,
Yr_Year int(4) not null,
primary key (Sec_ID),
foreign key (Crs_ID) references Course(Crs_ID),
foreign key (Per_ID) references Faculty(Per_ID),
foreign key (Trm_Num) references Term(Trm_Num),
foreign key (Yr_Year) references Year(Yr_Year)
);
create table Completion(
Cmp_ID int not null auto_increment,
Per_ID int not null,
Sec_ID int not null,
Grd_Sym char(2) not null,
primary key (Cmp_ID),
foreign key (Per_ID) references Person (Per_ID),
foreign key (Sec_ID) references Section (Sec_ID),
foreign key (Grd_Sym) references Grade (Grd_Sym)
);
create table Fulfillment(
Ful_ID int not null auto_increment,
Req_ID int not null,
Cmp_ID int not null,
primary key (Ful_ID),
foreign key (Req_ID) references Requirement(Req_ID),
foreign key (Cmp_ID) references Completion(Cmp_ID)
);
create table PreReq(
Prq_ID int not null auto_increment,
Crs_ID int(3) not null,
Prq_Crs_ID int(3) not null,
primary key (Prq_ID),
foreign key (Crs_ID) references Course(Crs_ID),
foreign key (Prq_Crs_ID) references Course(Crs_ID)
);
I have a problem.
I created a MySQL schema with the MySQL Workbench.
But there is a error message.
A comma or closing bracket was expected. (near "VISIBLE" at position 288)
Unexpected start of statement. (near "`ShopID`" at position 330)
Unrecognised statement type. (near "ASC" at position 339)
As I said I created the scheme via the MySQL workbench. But what is wrong ?
Note: PK = Primary Key; FK = Foreign Key.
Fact table:
Contaminants (TimeID (PK/FK), ShopID (PK/FK), FoodID (PK/FK), substance, quantityPerOunce)
Dimension tables:
Time (TimeID (PK), dayNr, dayName, weekNr, monthNr, year)
Food (FoodID (PK), foodName, brand, foodType)
Place (ShopID (PK), name, street, region, country)
CREATE TABLE IF NOT EXISTS `mydb`.`Contaminants` (
`TimeID` INT NOT NULL,
`ShopID` INT NOT NULL,
`FoodID` INT NOT NULL,
`substance` VARCHAR(45) NULL,
`quantityPerOunce` INT NULL,
PRIMARY KEY (`TimeID`, `ShopID`, `FoodID`),
UNIQUE INDEX `TimeID_UNIQUE` (`TimeID` ASC) VISIBLE,
UNIQUE INDEX `ShopID_UNIQUE` (`ShopID` ASC) VISIBLE,
UNIQUE INDEX `FoodID_UNIQUE` (`FoodID` ASC) VISIBLE,
CONSTRAINT `TimeID`
FOREIGN KEY (`TimeID`)
REFERENCES `mydb`.`Time` (`TimeID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `ShopID`
FOREIGN KEY (`ShopID`)
REFERENCES `mydb`.`Shop` (`ShopID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `FoodID`
FOREIGN KEY (`FoodID`)
REFERENCES `mydb`.`Food` (`FoodID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
CREATE TABLE IF NOT EXISTS `mydb`.`Food` (
`FoodID` INT NOT NULL,
`foodName` VARCHAR(45) NULL,
`brand` VARCHAR(45) NULL,
`foodType` VARCHAR(45) NULL,
PRIMARY KEY (`FoodID`))
ENGINE = InnoDB
CREATE TABLE IF NOT EXISTS `mydb`.`Shop` (
`ShopID` INT NOT NULL,
`INT` VARCHAR(45) NULL,
`street` VARCHAR(45) NULL,
`region` VARCHAR(45) NULL,
`country` VARCHAR(45) NULL,
PRIMARY KEY (`ShopID`))
ENGINE = InnoDB
CREATE TABLE IF NOT EXISTS `mydb`.`Time` (
`TimeID` INT NOT NULL,
`dayNr` INT NULL,
`dayName` VARCHAR(45) NULL,
`weekNr` INT NULL,
`monthNr` VARCHAR(45) NULL,
`year` INT NULL,
PRIMARY KEY (`TimeID`))
ENGINE = InnoDB
create table Employees
(
EmployeeID INT IDENTITY (1,1) PRIMARY KEY NOT NULL,
EmployeeName VARCHAR(255) NOT NULL,
EmployeeUsername VARCHAR(255) NOT NULL,
EmployeeEmail VARCHAR(255) NOT NULL,
GroupID INT FOREIGN KEY REFERENCES TypeOfGroup(GroupID),
Password VARCHAR(255) NOT NULL
);
create table TypeOfGroup
(
GroupID INT IDENTITY(1,1) PRIMARY KEY NOT NULL,
TypeGroup VARCHAR(255) NOT NULL,
Permission CHAR(1) NOT NULL
);
Question: I have a foreign key and wanted to make a connection with another table as I do this to insert into.
My foreign key is 'GROUPID'.
Try this...
insert into TypeOfGroup( TypeGroup, Permission) values ('hr', 1)
"this 1 is used for bit which is a data type in sql server 1 for true and 0 for false"
insert into Employees (EmployeeName, EmployeeUsername, EmployeeEmail,
GroupID, Password) values ('bruno', 'bruno', 'bruno#gmail.com', 1, 'urPassword')
and 1 in the 2nd query is primary of typeofgroup table.
I have a query that does what is required
SELECT v.* FROM vehicle v
WHERE v.company_id = 2 AND v.id NOT IN
(
SELECT h.vehicle_id
FROM hire h
WHERE
h.start_date is not null and h.end_date is null
)
So now I am trying to code this query in Symfony/Doctrine
I have this
$qb = $this->_em->createQueryBuilder();
$subq = $this->_em->createQueryBuilder();
$subq ->select('h.vehicle')
->from('AppBundle\Entity\Hire', 'h')
->andWhere('h.startDate is not null and h.endDate is null');
$qb->select('v')
->from('AppBundle\Entity\Vehicle', 'v')
->where($qb->expr()->notIn('v.id',$subq->getDQL()))
->andWhere('v.company = :company')
->setParameter('company', $company)
->orderBy('v.registrationNumber', 'ASC')
;
$t = $qb->getDQL();
return $qb;
As you see I tried dumping the DQL to see if that gave me any clues and here is is
SELECT v
FROM AppBundle\Entity\Vehicle v
WHERE (v.id NOT IN(SELECT h.vehicle FROM AppBundle\Entity\Hire h WHERE h.startDate is not null and h.endDate is null))
AND v.company = :company
ORDER BY v.registrationNumber ASC
I tried converting this back to simple SQL i.e. removing the AppBundle stuff and converting the column names back to actual column name and it runs and get the right result.
But I am getting this error
Doctrine\ORM\Query\QueryException:
[Semantical Error] line 0, col 69 near 'vehicle FROM': Error: Invalid PathExpression. Must be a StateFieldPathExpression.
at vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:63
at Doctrine\ORM\Query\QueryException::semanticalError('line 0, col 69 near \'vehicle FROM\': Error: Invalid PathExpression. Must be a StateFieldPathExpression.', object(QueryException))
The 2 tables involved are
CREATE TABLE `hire` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`driver_id` int(11) DEFAULT NULL,
`vehicle_id` int(11) DEFAULT NULL,
`corporate_hire` tinyint(1) DEFAULT NULL,
`end_date` datetime DEFAULT NULL,
`end_miles` decimal(10,1) DEFAULT NULL,
`start_date` datetime DEFAULT NULL,
`start_miles` decimal(10,1) DEFAULT NULL,
`created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`updated_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_B8017EFC979B1AD6` (`company_id`),
KEY `IDX_B8017EFCC3423909` (`driver_id`),
KEY `IDX_B8017EFC545317D1` (`vehicle_id`),
CONSTRAINT `FK_B8017EFC545317D1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_B8017EFC979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_B8017EFCC3423909` FOREIGN KEY (`driver_id`) REFERENCES `driver` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
and
CREATE TABLE `vehicle` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT NULL,
`storage_id` int(11) DEFAULT NULL,
`created_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`updated_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_by` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`deleted_at` datetime DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
`date_of_manufacture` datetime DEFAULT NULL,
`engine_size` int(11) DEFAULT NULL,
`make` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`model` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
`registration_number` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`vin` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `IDX_1B80E486979B1AD6` (`company_id`),
KEY `IDX_1B80E4865CC5DB90` (`storage_id`),
CONSTRAINT `FK_1B80E4865CC5DB90` FOREIGN KEY (`storage_id`) REFERENCES `storage` (`id`) ON DELETE SET NULL,
CONSTRAINT `FK_1B80E486979B1AD6` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
I am not sure what an Invalid Path Expression should be making me look for as an actual error.
What's working for us is (adapted to your example, so not tested):
$subQuery->select('IDENTITY(h.vehicle)');
$subQuery->from('AppBundle\Entity\Hire', 'h');
$dqlString = $subQuery->getQuery()->getDQL();
$query->andWhere('v.id' 'NOT IN (' . $dqlString . ')');
The only two differences that I see are:
subQuery returns IDENTITY() of h.vehicle, so only the 'identifier' (which is id in most cases)
our andWhere condition in main query is created manually - but your expression builder should work the same way.
So my assumption ist that your $subq ->select('h.vehicle') doesn't return ids which can be used in the NOT IN condition of your main query, which might be proven by your resolved DQL SELECT v : this will return all fields, but you'd required v.id only.
After creating an index on a rather small table (approx. 700 rows, 10 colums) I started to get
System.Data.SqlClient.SqlException: Timeout expired
The index was clusterd on the primary key.
There are no triggers.
All of these errors occured when doing an update via a stored procedure.
After I removed the index I had no more time-out issues.
Setting CommandTimeout did not help.
Does anybody has an idea why this was happening?
stored procedure (nothing special here)
Update objects set date_last_datacollect=#date_last_datacollect,
date_last_error='',message_last_error='' where objectid = #objectid
Table structure
CREATE TABLE [dbo].[objects](
[id] [int] IDENTITY(1,1) NOT NULL,
[objectid] [nvarchar](50) NULL,
[name] [nvarchar](max) NULL,
[adminid] [nvarchar](50) NULL,
[token] [nvarchar](max) NULL,
[type] [nvarchar](max) NULL,
[date_added] [date] NULL,
[date_last_update] [datetime] NULL,
[date_last_datacollect] [datetime] NULL,
[date_last_error] [datetime] NULL,
[message_last_error] [nvarchar](max) NULL,
[active] [bit] NULL,
[logourl] [nchar](255) NULL
) ON [PRIMARY]
edit:
After viewing my table structure I realize it might be due to the missing primary key?
Have you tried updating statistics on the table?