数据库基本操作
程序员文章站
2022-05-31 21:46:53
...
DDL(data defination language):
CREATE DATABASE 数据库名
DROP DATABASE 数据库名
mysqli_select_db(connection,dbname);//pdo—mysql
DROP TABLE 表名
INSERT INTO table_name(field1,field2...)values(value1,value2...);
SELECT field1,field2...FROM table_name /WHERE condition1 AND condition2
UPDATE table_name SET field1 = 'value1',field2 = 'value2' WHERE condition1 AND condition2
DELETE FROM table_name WHERE condition1 AND condition2
**LIKE子句**
SELECT field1,field2...FROM table_name WHERE field1 LIKE condition1 AND/OR field2 = 'somevalue'
**UNION操作符**
SELECT expression1,expression2...FROM table_name [WHERE conditions]
UNION [ALL | DISTINCT]
SELECT expression1,expression2...FROM table_name [WHERE conditions]
**MySQL排序**
SELECT field1,field2...FROM table_name ORDER BY field1[field2][ACE DESC]
**MYSQL分组**
SELECT column_name,function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name (WITH ROLLUP);
**MYSQL多表查询JOIN**
mysql> SELECT a.runoob_id, a.runoob_author, b.runoob_count FROM runoob_tbl a JOIN tcount_tbl b WHERE a.runoob_author = b.runoob_author;
**MySQL处理null**
IS NULL / IS NOT NULL
**MYSQL临时表**
TEMPORARY
类型 | 大小 | 范围(有符号) | 范围(无符号) | 用途 |
---|---|---|---|---|
TINYINT | 1 字节 | (-128,127) | (0,255) | 小整数值 |
SMALLINT | 2 字节 | (-32 768,32 767) | (0,65 535) | 大整数值 |
MEDIUMINT | 3 字节 | (-8 388 608,8 388 607) | (0,16 777 215) | 大整数值 |
INT或INTEGER | 4 字节 | (-2 147 483 648,2 147 483 647) | (0,4 294 967 295) | 大整数值 |
BIGINT | 8 字节 | (-9 233 372 036 854 775 808,9 223 372 036 854 775 807) | (0,18 446 744 073 709 551 615) | 极大整数值 |
FLOAT | 4 字节 | (-3.402 823 466 E+38,-1.175 494 351 E-38),0,(1.175 494 351 E-38,3.402 823 466 351 E+38) | 0,(1.175 494 351 E-38,3.402 823 466 E+38) | 单精度浮点数值 |
DOUBLE | 8 字节 | (-1.797 693 134 862 315 7 E+308,-2.225 073 858 507 201 4 E-308),0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308) | 0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308) | 双精度浮点数值 |
DECIMAL | 对DECIMAL(M,D) ,如果M>D,为M+2否则为D+2 | 依赖于M和D的值 | 依赖于M和D的值 | 小数值 |
DROP TABLE IF EXISTS `shop_user`;
CREATE TABLE `shop_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL COMMENT '名称',
`phone` varchar(20) NOT NULL COMMENT '手机',
`pass` varchar(255) NOT NULL COMMENT '密碼',
`logo` varchar(255) NOT NULL COMMENT '頭像路徑',
`money` decimal(12,2) NOT NULL COMMENT '零錢',
`status` tinyint(3) NOT NULL DEFAULT '1' COMMENT '狀態 1:正常;2:禁用',
`isvalid` bit(1) NOT NULL COMMENT '是否有效',
`date` datetime NOT NULL COMMENT '创建时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COMMENT='用户表';