Created
July 19, 2012 18:48
-
-
Save omerucel/3145941 to your computer and use it in GitHub Desktop.
sample shop schema for blog post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; | |
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; | |
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; | |
CREATE SCHEMA IF NOT EXISTS `shop` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ; | |
USE `shop` ; | |
-- ----------------------------------------------------- | |
-- Table `shop`.`musteri` | |
-- ----------------------------------------------------- | |
DROP TABLE IF EXISTS `shop`.`musteri` ; | |
CREATE TABLE IF NOT EXISTS `shop`.`musteri` ( | |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT , | |
`isim` VARCHAR(45) NOT NULL , | |
PRIMARY KEY (`id`) ) | |
ENGINE = InnoDB; | |
-- ----------------------------------------------------- | |
-- Table `shop`.`urun` | |
-- ----------------------------------------------------- | |
DROP TABLE IF EXISTS `shop`.`urun` ; | |
CREATE TABLE IF NOT EXISTS `shop`.`urun` ( | |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT , | |
`baslik` VARCHAR(255) NULL , | |
`fiyat` FLOAT UNSIGNED NOT NULL , | |
PRIMARY KEY (`id`) ) | |
ENGINE = InnoDB; | |
-- ----------------------------------------------------- | |
-- Table `shop`.`adres` | |
-- ----------------------------------------------------- | |
DROP TABLE IF EXISTS `shop`.`adres` ; | |
CREATE TABLE IF NOT EXISTS `shop`.`adres` ( | |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT , | |
`musteri_id` INT UNSIGNED NOT NULL , | |
`adres` VARCHAR(255) NULL , | |
INDEX `fk_musteri_adres_musteri_id` (`musteri_id` ASC) , | |
PRIMARY KEY (`id`) , | |
CONSTRAINT `fk_musteri_adres_musteri_id` | |
FOREIGN KEY (`musteri_id` ) | |
REFERENCES `shop`.`musteri` (`id` ) | |
ON DELETE CASCADE | |
ON UPDATE NO ACTION) | |
ENGINE = InnoDB; | |
-- ----------------------------------------------------- | |
-- Table `shop`.`siparis` | |
-- ----------------------------------------------------- | |
DROP TABLE IF EXISTS `shop`.`siparis` ; | |
CREATE TABLE IF NOT EXISTS `shop`.`siparis` ( | |
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT , | |
`musteri_id` INT UNSIGNED NOT NULL , | |
`urun_id` INT UNSIGNED NOT NULL , | |
`address_id` INT UNSIGNED NOT NULL , | |
INDEX `fk_musteri_siparis_musteri_id` (`musteri_id` ASC) , | |
INDEX `fk_urun_siparis_urun_id` (`urun_id` ASC) , | |
INDEX `fk_adres_siparis_adres_id` (`address_id` ASC) , | |
PRIMARY KEY (`id`) , | |
CONSTRAINT `fk_musteri_siparis_musteri_id` | |
FOREIGN KEY (`musteri_id` ) | |
REFERENCES `shop`.`musteri` (`id` ) | |
ON DELETE CASCADE | |
ON UPDATE NO ACTION, | |
CONSTRAINT `fk_urun_siparis_urun_id` | |
FOREIGN KEY (`urun_id` ) | |
REFERENCES `shop`.`urun` (`id` ) | |
ON DELETE CASCADE | |
ON UPDATE NO ACTION, | |
CONSTRAINT `fk_adres_siparis_adres_id` | |
FOREIGN KEY (`address_id` ) | |
REFERENCES `shop`.`adres` (`id` ) | |
ON DELETE CASCADE | |
ON UPDATE NO ACTION) | |
ENGINE = InnoDB; | |
SET SQL_MODE=@OLD_SQL_MODE; | |
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; | |
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment