SQL基本操作


前言

本文主要记录sql基本操作的相关笔记


–操作之前必须首先新建数据库,使用下列语句即可

create database test1;

–建表之前要先使用use语句声明使用了哪个数据库

use test1;
create table table1(
id smallint(5) not null primary key,
first_name varchar(45) not null DEFAULT 'uuu',
last_name varchar(45) not null DEFAULT 'ttt' 
);

–更改first_name字符长度为50

ALTER TABLE `test1`.`table1` 
CHANGE COLUMN `first_name` `first_name` VARCHAR(50);

–添加数据

insert into table1 values
(1,'a','b'), (2,'a','b'), (3,'a','b')

–清空数据

drop table if exists table1;

–增加一列数据并赋默认值

alter table table1 add create_date datetime not null DEFAULT '2020-10-01 00:00:00'

–建立索引

create index idx_last on table1(last_name)

–强制索引查找

select * from table1 t1 FORCE INDEX (idx_last) 

select case when max(s)%2=1 then max(s)/2
select grade,sum(number)over(order by grade)s from class_grade

–删除表table1

drop table if exists table1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sky-JT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值