首页 > 数据库技术 > 详细

简单的SQL语句学习

时间:2020-07-08 00:08:22      阅读:93      评论:0      收藏:0      [点我收藏+]
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 ;

 

简单的SQL语句学习

原文:https://www.cnblogs.com/ma1998/p/13263749.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!