当前位置:网站首页>DAY4:SQL Sever 简单使用
DAY4:SQL Sever 简单使用
2022-07-29 05:19:00 【EdmunDJK】
DAY4:SQL Sever 简单使用
1、新建数据库
点击文件,点击新建,点击使用当前连接的查询
create database 数据库名//创建
drop database 数据库名//删除

使用命令新建数据库,名字为 book ,点击执行刷新左边管理器可以看到已经新添加了一个空的数据库

2、新建表
创建表,并且添加相应数据
create table 表名
(
列名称1 数据类型,
列名称2 数据类型,
....
)
实例:
create table bookssss
(
goodstudent varchar(50),
number int,
reader varchar(50),
story varchar(50)
)

刷新一下 book 可以发现出现了个新表,右键点击编辑前200列可以看出效果
如果要删除表,则可以使用下面的命令
drop table 表名//第一种,直接删除不能新增数据
truncate table 表名//第二种,删除表中数据,定义还在,可以增添数据
delete table 表名//第三种,删除表中数据不删除结构,增添数据,id会从删除的最后一条开始
3、常用的查询命令
3.1、select用法
作用:从表中选取自己想要得到的数据
select * from 表名//第一种,选取表中的所有列,*表示所有列
select 列名1,列名2 from 表名//第二种,选取部分列
3.2、distinct用法
作用:返回列中唯一不同的值(表中有可能存在重复的值,重复的值只返回一种)
distinct *from 表名//返回所有列中,每列不同的值
distinct 列名1,列名2 from 表名//返回部分列中
3.3、where用法
作用:代表范围
select * from 表名
where 列名1='某个数据'
实例:
select * from 超市信息
where goodsname='可口可乐'//查询出可口可乐的所有信息
3.4、AND和OR用法
作用:and并,or或
select * from 表名
where 列名1='xxxx' or 列名2='yyyy'
select * from 表名
where 列名1='xxxx' and 列名2='yyyy'
实例:
select * from 超市信息
where goodstype='膨化食品' and goodsfoctory='康师傅'
3.5、ORDER BY用法
作用:默认按照升序排序
select 列名1,列名2 from 表名
order by 需要根据排序的列名//之后加上desc的话,是逆序排列
实例:
select goodstype,goodsname from 超市信息
order by goodsname
insert用法
作用:在表中插入新的数据
insert into 表名 values('xxx','xxx','xxx','xxx')
insert into 表名 (列名1,列名2,列名3,列名4) values('xxx','xxx','xxx','xxx')
可以重复使用
3.6、update用法
作用:修改表中的数据
update 表名 set 列名1='你要修改的值' where 列名2='你用来确定的哪行的数据'
实例:
update 超市信息 set goodsname='冰红茶' where goodsfactory='康师傅'
//把厂家为康师傅的产品的名称改为冰红茶
delete用法
作用:删除
delete 表名 where 列名='xxx'//删除xxx所在的那一行
pdate 超市信息 set goodsname=‘冰红茶’ where goodsfactory=‘康师傅’
//把厂家为康师傅的产品的名称改为冰红茶
delete用法
作用:删除
delete 表名 where 列名=‘xxx’//删除xxx所在的那一行
边栏推荐
- Day 3
- Dynamic sorting of DOM object element blocks in applets
- Basic concepts of MySQL + database system structure + extended application + basic command learning
- link与@import的关系
- Merge the same items in the same column in table
- ClickHouse学习(十一)clickhouseAPI操作
- Wechat applet video upload component is directly uploaded to Alibaba cloud OSS
- Relative positioning and absolute positioning
- 组件传参与生命周期
- Solve the problem that the prompt information of form verification does not disappear and the assignment does not take effect
猜你喜欢

Day14: upload labs customs clearance tutorial

Hcia-r & s self use notes (24) ACL

Pyqt5: Chapter 1, Section 1: creating a user interface using QT components - Introduction

Clickhouse learning (VI) grammar optimization

Win10 搭建MSYS2环境

About local variables

DAY15:文件包含漏洞靶场手册(自用 file-include 靶场)

虚拟增强与现实第二篇 (我是一只火鸟)
![[typescript] type reduction (including type protection) and type predicate in typescript](/img/74/52fe769ed3850e01d97cb9fefb7373.png)
[typescript] type reduction (including type protection) and type predicate in typescript

Qframe class learning notes
随机推荐
[electronic circuit] how to select ADC chip
TXT 纯文本操作
Fvuln-自动化web漏洞检测工具
Global components component registration
Installation steps and environment configuration of vs Code
Wapiti是什么以及使用教程
Win10 搭建MSYS2环境
Wechat applet video upload component is directly uploaded to Alibaba cloud OSS
[C language series] - print prime numbers between 100 and 200
sql-server 数据表的简单操作
Terminal shell common commands
弹性盒子flex
js简单代码判断打开页面的设备是电脑PC端或手机H5端或微信端
[C language series] - three methods to simulate the implementation of strlen library functions
字符类型转换
Qframe class learning notes
Masscan使用教程.
365 day challenge leetcode1000 question - day 036 binary tree pruning + subarray and sorted interval sum + delete the shortest subarray to order the remaining arrays
Qt布局管理--部件拉伸(Stretch)原理及大小策略(sizePolicy)
Qt设置背景图片方法