foreign-keys

MySQL InnoDB constraint does not work

被刻印的时光 ゝ 提交于 2019-12-02 13:08:45
问题 I stumble upon strange behavior with innoDB constraint, and cannot find cause of it. I have tables with data. Below listed their structures: CREATE TABLE `contents` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`), KEY `title` (`title`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `fields` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, `type` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY

Foreign key issue:ERROR 1005 (HY000): Can't create table (errno: 150)

蹲街弑〆低调 提交于 2019-12-02 11:37:37
I'm getting this error: ERROR 1005 (HY000): Can't create table (errno: 150); I know it has something to do with the foreign keys but I have checked to see if they have the same info types etc and I can't find the problem. The video, director actor, role and member create; the rest do not. CREATE TABLE IF NOT EXISTS actor ( actorNo VARCHAR(15) NOT NULL, actorName VARCHAR(40) NOT NULL, PRIMARY KEY (actorNo) ) ENGINE=InnoDB; CREATE TABLE IF NOT EXISTS staff ( StaffNo VARCHAR (15) NOT NULL, name VARCHAR(40) NOT NULL, position VARCHAR(40) , salary FLOAT(5,2) , branchNo VARCHAR(15) NOT NULL, FOREIGN

error in mysql syntax

陌路散爱 提交于 2019-12-02 10:41:08
问题 while executing the following query, i get an error that there's an error in the syntax near line 9. since i'm using mysql workbench, i can't really figure out what could be wrong: CREATE TABLE IF NOT EXISTS `proquotes`.`thquotes` ( `idQuotes` INT NOT NULL AUTO_INCREMENT , `vAuthorID` VARCHAR(8) CHARACTER SET 'utf8' NOT NULL , `vAuthor` VARCHAR(45) CHARACTER SET 'utf8' NOT NULL , `cQuotes` MEDIUMTEXT CHARACTER SET 'utf8' NOT NULL , `cArabic` MEDIUMTEXT CHARACTER SET 'utf8' NOT NULL ,

Database : what design to point on two possibilities?

可紊 提交于 2019-12-02 08:28:50
问题 I am designing a datamodel for a new project. One of the requirements specifies that some objects can point either a person or a company. What is the smartest way to achieve that? I have thought about a table link "actor" like this (drawn with the excellent yUML.me BTW) : In the actor table, according to actor_type , person_id or company_id is a foreign key on its corresponding table or is NULL . This way, when one_table wants to retrieve details about the actor , I start by checking the

primary key and foreign key

丶灬走出姿态 提交于 2019-12-02 07:56:09
问题 I have 3 tables Student Loan Book - StudentID LoanID BookID which foreign keys do i need to set so when given the student name, search all loan from that student and display the book detail 回答1: Here's a start with such vague requirements: CREATE TABLE dbo.Students ( StudentID INT PRIMARY KEY -- , other columns about students ); CREATE TABLE dbo.Loans ( LoanID INT PRIMARY KEY, StudentID INT NOT NULL FOREIGN KEY REFERENCES dbo.Students(StudentID) -- , other columns about loans ); CREATE TABLE

MySQL best approach for db normalising, relationships and foreign keys

六眼飞鱼酱① 提交于 2019-12-02 07:38:18
There is an username/password verification step first then the database has following structure ^ is primary key * uses foreign key 1.StudentDetails table =========================================================================== ID^| Username | Password | Email | Address * | Website |Comments ====+============+==========+=============+===========+=========+========== 1 | xxxxxxxxxx | xxxxxxx | xx@xxx.xxx | 1 | http:// | text 2.Submissions table =========================================================================================== ID^|Username*|SubmitDate|SelectedCourse*|Price*|Promotion

Hibernate - Composite Primary Key contains Foreign Key

放肆的年华 提交于 2019-12-02 07:29:22
问题 I have a similar question as below, but the solution didn't solve my problem. hibernate composite Primary key contains a composite foreign key, how to map this I am trying to join 2 tables, each having a composite primary key with partial foreign key reference. Table A -------- f1 (pk) f2 (pk) f3 (pk) f4 (pk) Table B -------- f1 (pk, fk) f2 (pk, fk) f5 (pk) f6 (pk) I created A, APK, B, BPK In A: private Set<B> bSet; @OneToMany(targetEntity=B.class, cascade = CascadeType.ALL, mappedBy= "bpk.a"

ERROR 1005 (HY000): Can't create table 'shrewd_db.alert_disable_register' (errno: 150)

不想你离开。 提交于 2019-12-02 07:16:03
问题 I want to create a table in MySQL by running following SQL, CREATE TABLE IF NOT EXISTS `shrewd_db`.`alert_disable_register` ( `id_alert_disable_register` MEDIUMINT NOT NULL AUTO_INCREMENT, `id_label` MEDIUMINT UNSIGNED NULL, `id_indicator` MEDIUMINT UNSIGNED NULL, `id_user` MEDIUMINT UNSIGNED NULL, `active` TINYINT(1) NULL DEFAULT 1, `id_alert_disable_rule` MEDIUMINT NULL, `id_escalation_plan` INT NULL, PRIMARY KEY (`id_alert_disable_register`), INDEX `id_escalation_plan_alert_rule_idx` (`id

error in mysql syntax

一世执手 提交于 2019-12-02 07:12:40
while executing the following query, i get an error that there's an error in the syntax near line 9. since i'm using mysql workbench, i can't really figure out what could be wrong: CREATE TABLE IF NOT EXISTS `proquotes`.`thquotes` ( `idQuotes` INT NOT NULL AUTO_INCREMENT , `vAuthorID` VARCHAR(8) CHARACTER SET 'utf8' NOT NULL , `vAuthor` VARCHAR(45) CHARACTER SET 'utf8' NOT NULL , `cQuotes` MEDIUMTEXT CHARACTER SET 'utf8' NOT NULL , `cArabic` MEDIUMTEXT CHARACTER SET 'utf8' NOT NULL , `vReference` VARCHAR(100) CHARACTER SET 'utf8' NOT NULL , PRIMARY KEY (`idQuotes`) , INDEX `vAuthorID` () ,

Database : what design to point on two possibilities?

≡放荡痞女 提交于 2019-12-02 06:53:08
I am designing a datamodel for a new project. One of the requirements specifies that some objects can point either a person or a company. What is the smartest way to achieve that? I have thought about a table link "actor" like this (drawn with the excellent yUML.me BTW) : In the actor table, according to actor_type , person_id or company_id is a foreign key on its corresponding table or is NULL . This way, when one_table wants to retrieve details about the actor , I start by checking the actor_type field and retrieve either person_id or company_id . It is working, but I am looking for a better