简单的SQL语句学习
CREATE DATABASE db_test; USE db_test; CREATE TABLE USER( uid INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(30) NOT NULL, PASSWORD VARCHAR(30) NOT NULL, uname VARCHAR(10) NOT NULL, phone VARCHAR(11) UNIQUE ) /* 数据库增加 */ INSERT INTO USER(uid,username,PASSWORD,uname,phone) VALUES(NULL,"马文飞","123456","马文飞","16637809505"); INSERT INTO USER(uid,username,PASSWORD,uname,phone) VALUES(NULL,"翟华兵","123456","翟华兵","16637809506"); /* 数据库更改 */ UPDATE USER SET phone = "16637801234" WHERE uid = 2; /* 数据库删除 */ DELETE FROM USER; DELETE FROM USER WHERE uname = "马文飞"; #将这张表删除,再创建一个新表,是新的主键索引 TRUNCATE TABLE USER; /* 查看数据库 */ SELECT uname,phone FROM USER; SELECT uname,phone FROM USER WHERE uid = "1"; SELECT MAX(uid) FROM USER; SELECT MIN(uid) FROM USER; SELECT SUM(uid) FROM USER; SELECT AVG(uid) FROM USER; SELECT COUNT(uid) FROM USER; #按照uid降序排列 SELECT * FROM USER ORDER BY uid DESC; SELECT * FROM USER ORDER BY uid ;
代码成就万世基积沙镇海
梦想永在凌云意意气风发