欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

sql基础知识点

程序员文章站 2022-06-01 22:01:26
...

1.用到SQL(structured query language )处理的数据库:mysql,access,SQL server,oracle,DB2,Sybase等.

2.RDBMS(relational database management system):关系型数据库管理系统

#(使用SQLyog)创建一个数据库语句

CREATE DATABASE practive

#创建一个表

CREATE TABLE Websites( 
id INT(5) NOT NULL AUTO_INCREMENT, 
NAME VARCHAR(10) NOT NULL, 
url VARCHAR(50) NOT NULL, 
alexa INT(10) NOT NULL, 
country VARCHAR(10) NOT NULL, 
PRIMARY KEY (`id`) 
) ENGINE=INNODB CHARSET=utf8; 

#插入数据

INSERT INTO websites (NAME,url,alexa,country) VALUES
('Google','https://www.google.cm/',1,'USA');

INSERT INTO websites(NAME,url,alexa,country) VALUES
('淘宝','https://www.taobao.com/',13,'CN')

INSERT INTO websites(NAME,url,alexa,country) VALUES
('菜鸟教程','http://www.runoob.com/ ',4689,'CN')

INSERT INTO websites(NAME,url,alexa,country) VALUES
('微博','http://weibo.com/',20,'CN');

INSERT INTO websites(NAME,url,alexa,country) VALUES
('Facebook',' https://www.facebook.com/ ',3,'USA')

#表图:
sql基础知识点
#查询语句

SELECT NAME,url FROM practive.`Websites`;

sql基础知识点

#查询一个列段的不重复显示

SELECT DISTINCT country FROM websites;

sql基础知识点

#要以两个列进行排序中间用逗号,而不是and符号

SELECT*FROM websites GROUP BY country,alexa

sql基础知识点
#更新表数据

UPDATE websites SET alexa = 5000,country='USA' WHERE NAME = '菜鸟教程'

#删除表特殊字段

DELETE FROM websites WHERE NAME='Facebook' AND country = 'USA';

#整理基础语言

SELECT*FROM websites 
WHERE country = 'CN' 
GROUP BY alexa DESC

sql基础知识点