SQL Server第一堂课:创建数据库,创建表,以及表中最基本的增,删,改

在新建查询里输入代码创建数据库以及数据库中的表

create database xuesheng  --创建数据库,xuesheng为数据库的库名
drop database xuesheng   --删除数据库,命令没有执行
use xuesheng --使用数据库,命令已经执行
go
create table xuesheng  --创建表,要和下面的表的列一起执行命令,才能新建,xuesheng为数据库中表的名
(
name varchar(50) not null, --新建表中的列
code int not null,    --新建表中的列    //primary key indentity(1,1)  定义主键,加一个indentity(1,1)是把列设置为自然增长列
fenshu int not null,
sex int
)
go
select *from xuesheng --显示所创建的学生表格 ,//这句代码很重要
go
insert into xuesheng values('张三',1,87,0)    //输入表格中的具体信息,按照列中的格式,字符串需要加单引号
insert into xuesheng values('李四',2,89,0)   //定义为自然增长列时,增长列中数据可不用输入
insert into xuesheng values('王五',3,85,1)
insert into xuesheng values('赵六',4,90,1)
go
update xuesheng set sex=1 --修改所在行中的sex列的值
update xuesheng set sex=0  where code=3--修改所在学号3行中的sex列的值
update xuesheng set name ='' ,code=3,fenshu =60,sex=0  where code=4--修改所在4行中所有的值
go
delete from xuesheng --删除表中所有数据
delete from xuesheng where code=2 --删除表中code2所在的第二行
drop table xuesheng --删除这个表

 select *from xueshengxinxi where age between 18 and 20    //查询方法
                                             select *from xueshengxinxi where name  like '张%'--like '%李'     like'%四%'  //查询方法
原文地址:https://www.cnblogs.com/275147378abc/p/4434621.html