Jump to content
php.lv forumi

MySql dažām tabulām ir uzlicies 'Links to', kas tas tāds?


Sasa

Recommended Posts

Kaut kā šādi izskatās!

Bažijos par Links to (product -> ID), jo nezinu kas tas tāds.

 

Field  	   Type   	 Null  	 Default   	 Links to  	 Comments  	 MIME
accs_id    bigint(20) 	 No  	  	  	  	 
product_id bigint(20) 	 Yes  	 NULL  	         product -> ID  	  	 
drillQty   bigint(20) 	 Yes  	 NULL  	  	  	 
fas2 	   double(20,20) Yes  	 NULL  	  	  	 
korp08 	   double(20,20) Yes  	 NULL  	  	  	 
fas04 	   double(20,20) Yes  	 NULL  	  	  	 
fas2fig    double(20,20) Yes  	 NULL  	  	  	 
korp08fig  double(20,20) Yes  	 NULL  	  	  	 
mel 	   double(20,20) Yes  	 NULL  	  	  	 
picture    varchar(200)  Yes  	 NULL  	  

Link to comment
Share on other sites

Un? Uz ko tas norāda? Jā man ir tāda tabula 'product' ar lauku 'ID'.

Vot kā man ir man ir product tabula un šai produkt tabulai nāk blakus vēl divas tabulas kurās figurē produkta ID, lai es velāk varētu atrast kas attiecās uz šo produktu, tad lai paliek tie Foreign key ??

Link to comment
Share on other sites

Tas norāda MySQL'am, ka vērtības product_id referencējas uz ID vērtībām tabulā products. Parasti tas palīdz nodrošināt datubāzes integritāti. Piemēram, dzēšot kādu produkta tabulas ierakstu visi attiecīgi citu tabulu ieraksti, kuri referencējas uz dzēšāmo produktu, arī tiks automātiski dzēsti (vai arī dzēšana tiks aizliegta, atkarībā no ārējās atslēgas uzstādījumiem).

 

Tavu pēdējo jautājumu nesapratu. Kā izselektēt tos produktus? Ar parastu JOIN'u:

SELECT x.*, product.* FROM x JOIN products ON x.product_id = product.id

Link to comment
Share on other sites

Tabulas:

 

Product

CREATE TABLE `product` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`code` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`description` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=359 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

 

Details

CREATE TABLE `details` (
`det_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`product_id` bigint(20) unsigned NOT NULL,
`lenght` bigint(20) unsigned NOT NULL,
`mel1` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`abs1` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`width` bigint(20) unsigned NOT NULL,
`mel2` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`abs2` varchar(10) COLLATE utf8_unicode_ci DEFAULT NULL,
`qtn` bigint(20) unsigned NOT NULL,
`type` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
`detNr` bigint(20) unsigned NOT NULL,
`image` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`det_id`),
UNIQUE KEY `det_id` (`det_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

 

Accessories

CREATE TABLE `accessories` (
`accs_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`product_id` bigint(20) unsigned DEFAULT NULL,
`drillQty` bigint(20) unsigned DEFAULT NULL,
`fas2` double(20,20) DEFAULT NULL,
`korp08` double(20,20) DEFAULT NULL,
`fas04` double(20,20) DEFAULT NULL,
`fas2fig` double(20,20) DEFAULT NULL,
`korp08fig` double(20,20) DEFAULT NULL,
`mel` double(20,20) DEFAULT NULL,
`picture` varchar(200) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`accs_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

 

Bet te neparādās Foreign key !? MySQL pats izdomāja ..

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...