当前位置:网站首页>SQL language (foundation 1)
SQL language (foundation 1)
2022-07-22 17:29:00 【Mourning】
Today we begin to contact a new language Sql Language , stay 21 century , The most valuable thing is data , Should we take some of these data and store them ,Sql Language is such a container for storing data , Today, let's explore Sql The true face of Lushan !!!
Database Overview
1. Why study databases :
● Realize data persistence to local ;
● Use a complete management system for unified management , It can realize structured query , Easy to manage ;
2. Database related concepts :
- DB: database (DataBase) A container for storing data , It holds a series of organized data .
- DBMS: Database management system (DataBase Management System) Also known as database software or database products , Used to create or manage DB.
- SQL: Structured query language (Structure Query Language) The language used to communicate with the database , It's not unique to any database software , It's almost all
- Common language of mainstream database software .
3. According to different data types, it can be divided into :
Relational database :
- A relational database management system is called RDBMS,R finger Relation
- Oracle: Powerful , charge .
- MySQL quick 、 reliable Open source 、 free
- SQL Server( Microsoft ): Can only be installed in Windows operating system
- DB2 (IBM)
- MongdoDB
- Redis
- Case insensitive , It is suggested to capitalize the keywords , Table name 、 Column names in lowercase
- Use every word ;
- Single-line comments :# Note text
- Single-line comments :
- Note text ( There should be spaces )
- Multiline comment :
- /* Note text */
DDL
● data ( structure ) Define language DDL(Data Definition Language), Is a language used to create and modify database table structure .
● Common sentences :create ,alter,drop,rename
Create a database and set the encoding formatCREATE DATABASE [if not exists] Database name [ CHARSET utf8]
Delete database
DROP DATABASE Database name / [IF EXISTS Database name ];
Modify character setALTER DATABASE Database name CHARSET gbk;
- Put the data in the table , Put the watch in the library
- There can be multiple tables in a database , Every watch has a name , To identify yourself . Table names are unique .
- Table has some characteristics , These properties define how data is stored in tables , similar Java in “ class ” The design of the .
- Table consists of columns , We also call columns fields . All tables are made up of one or more columns , Each column is similar to java Medium ” attribute ”
- The data in the table is stored by row , Each line is similar to Java Medium “ object ”.
Design table data type
- char(n) The length is n Fixed length string
- varchar(n) Maximum length is n Variable length string
- date date ,
- Including mm / DD / yyyy
- datetime Specific date Minutes and seconds
Delete tableDROP TABLE [if exists ] Table name
Modify the name of the tableRENAME TABLE The old name of the table TO The new name of the table
Replicated table structureCREATE TABLE The new name of the table LIKE Copied table name ;
insert dataThe way 1: INSERT INTO Table name ( Column 1, Column 2……, Column n) VALUES( value 1, value 2….., value n);The way 2: INSERT INTO Table name set Name 1= value 1,.. Name n= value n;The way 3: INSERT INTO Table name ( Column 1, Column 2……, Column n) VALUES( value 1, value 2….., value n),( value 1, value 2….., value n);The way 4:INSERT INTO Table name ( Column 1, Column 2……, Column n) Query statement ( The number of columns queried matches the number of inserted columns )
Modifying dataUPDATE Table name SET Name = ‘ The new value ’WHERE Conditions
Delete dataDELETE FROM Table name WHERE ConditionsTRUNCATE TABLE Table name ; Clear the whole table
A little practice :
CREATE DATABASE baseketballteam;
CREATE TABLE basketball(
Team number INT PRIMARY KEY,
Team name VARCHAR(5),
home VARCHAR(5)
)
CREATE TABLE basketmember(
Number INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(10),
Birthday DATE,
height DOUBLE(3,2) CHECK( height >1.8),
weight INT,
Location VARCHAR(5)
)
#drop table basketmember
INSERT INTO basketmember( name , Birthday , height , weight , Location )
VALUES(' Dwayne . wade ','1982-1-17',1.93,96,'null'),
(' lebron . James ','1984-12-30',2.03,113,' striker '),
(' Kobe . Bryant ','1978-8-23',1.92,99,' defender '),
(' Deco . Dirk Nowitzki ','1978-6-19',2.13,111,'null'),
(' Iris . Paul ','1985-5-6',1.82,79,' defender '),
(' Tony . Parke ','1982-5-17',1.87,83,' defender '),
(' Kevin . Garnett ','1981-7-14',2.12,113,'null'),
(' Paul . Pierce ','1977-10-13',2.00,106,' striker '),
(' Michael . Jordan ','1963-2-17',1.98,98,' striker '),
(' Dwight - Howard ','1985-12-18',2.10,120,' Center-forward '),
(' Yao Ming ','1980-9-12',2.29,140,' Center-forward '),
(' Shaquille . O'Neill ','1972-3-6',2.15,147,' Center-forward ')
UPDATE basketmember SET Location =' Center-forward ' WHERE Number =1
DELETE FROM basketmember WHERE Number =12
边栏推荐
- -bash-4.2$
- MySQL constraint_ Primary key constraint primary key
- [machine learning] how pytorch loads custom datasets and divides them
- MySQL constraint_ Non empty constraint
- 1312. Minimum number of inserts to make a string a palindrome string
- 2022年暑假ACM热身练习3(部分题目总结)
- Web3流量聚合平台Starfish OS,给玩家元宇宙新范式体验
- Cause du tampon / cache du serveur et libération du tampon / cache
- Write a sequencer plug-in sequence subtitle (1)
- mysql约束之_非空约束
猜你喜欢
随机推荐
Atomicinteger class is used in multithreading to ensure thread safety
MVC模式和三层架构
Threads and processes
What are the ways of configuring Apache virtual hosts
1312. 让字符串成为回文串的最少插入次数
牛客网 Fibonacci数列
2022年暑假ACM热身练习3(部分题目总结)
Understand five popular NFT delivery methods and their advantages and disadvantages
并发程序的噩梦——数据竞争
Li Hongyi machine learning 2020--p20 & 21 RNN
LCD notes (1) LCD hardware operation principle of different interfaces
一个注解实现方法返回数据写入缓存(切面、Redis实现)
Distributed computing framework map/reduce
What is I18N and what is its function
CASTOR 通过 Polygonica 3D引擎实现云端大型装配进行高吞吐量分析,HOOPS Exchange助力其实现对 CAD 数据文件读取
【学习笔记之菜Dog学C】深入理解数组与指针
LCD笔记(1)不同接口的LCD硬件操作原理
NPM warn config global ` --global `, `--local` are deprecated Use `--location=global` instead.
Castor realizes high-throughput analysis of large-scale cloud assembly through polygonica 3D engine, and hoops exchange helps it read CAD data files
UE4 面试基础知识(三)