- The + + PRIMARY key (primary key) uniquely identifies a row in the table for a property or attribute group + +. = = A table can have only one primary key = =, but may have multiple candidate indexes. = = Primary key can guarantee record unique = = and = = Primary key domain not empty = =, the database management system automatically generates a unique index for the primary key, so the primary key is also a special index.
-
Remember:
1. The value of the primary key is unique
2. A data table can have only one primary key
3. The value of the primary key cannot be null
Increment: Add a piece of data to the table
INSERT INTO `表名`(`列名1`, `列名2`, `列名3`) VALUES (数字1,‘字符串2‘,‘内容3‘) insert into 表名(字段1,字段2,……) values(值1,值2,……) insert into scoretab (sname,h5,js) values(‘$sname‘,$h5,$js)
Exp:
INSERT INTO `users`(`uid`, `uname`, `upwd`) VALUES (5,‘小刀‘,001)
By deleting:
DELETE FROM `表名` WHERE (判断条件)1. Delete from 表名 清空表数据(慎重使用)2. Delete from 表名 where 字段=值3. 删除编号为3的产品delete from pro where pid = 34. 删除 小米 手机这个产品delete from pro where name = ‘小米’ delete from `scoretab` where sid=$id
Exp:
DELETE FROM `users` WHERE uid = 6(判断条件)
Change:
UPDATE `表名` SET `列名1`=[value-1],`列名2`=[value-2],`列名3`=[value-3] WHERE (条件)1. Update 表名 set 字段 = 值, 字段 = 值, …… where 条件2. 修改 小米手机价格是 3000update product set price = 3000 where pname=”小米” update scoretab set sname =‘$sname‘,h5 = $h5,js = $js where sid = $sid
Exp:
UPDATE `users` SET `upwd`= 666 WHERE uid = 8
Check:
SELECT `uid`, `uname`, `upwd` FROM `users` WHERE (条件)1. Select * from 表名 查询所有的数据2. Select pname,price from 表名 查询指定的列3. Select * from 表名 where 条件 按照条件查询4. 查询编号为7的商品select * from 表名 where pid = 7 select * from scoretab where sid = $id //通配符,查找所有
Exp:
SELECT `uid`, `uname`, `upwd` FROM `users` WHERE uname = ‘小明‘
18. MySQL