MySQL數據庫的對象有:數據庫、表、視圖、存儲過程、函數、觸發器、事件等。
創建數據庫: CREATE DATABASE `mydb`; 創建表: CREATE TABLE `mytable` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', `age` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; 創建視圖: CREATE VIEW `myview` AS SELECT `name`, `age` FROM `mytable` WHERE `age` >18; 創建存儲過程: CREATE PROCEDURE `myproc` (IN `myname` VARCHAR(50), OUT `myage` INT) BEGIN SELECT `age` INTO `myage` FROM `mytable` WHERE `name` = `myname`; END; 創建函數: CREATE FUNCTION `myfunc` (`name` VARCHAR(50)) RETURNS INT BEGIN DECLARE `myage` INT; SELECT `age` INTO `myage` FROM `mytable` WHERE `name` = `name`; RETURN `myage`; END; 創建觸發器: CREATE TRIGGER `mytrigger` BEFORE INSERT ON `mytable` FOR EACH ROW BEGIN SET NEW.`name` = UPPER(NEW.`name`); END; 創建事件: CREATE EVENT `myevent` ON SCHEDULE EVERY 1 DAY DO DELETE FROM `mytable` WHERE `age`< 18;
上一篇css圖片右居中
下一篇mysql數據庫的官網