select *from student--查询数据库
create database s20150417 --新建数据库
drop database [20150325] --删除数据库 数字开头的需要用[]括起
use s20150417 --使用数据库
go --连接符 不写也可以
create table student--创建表
(
code int not null,--列
name varchar(50) not null,--列
sex int,--列
degree decimal(18,2) not null--列
)
go
insert into student values(1,'张三',0,99);--插入数据 对应上面建的表 四列插入数值 对应数据类型
insert into student values(3,'李四',1,87);
insert into student(code,name,degree) values(4,'王五',87);--指定列添加
go
update student set sex=0
update student set sex=0 where code=3 --修改某一列的数值 用where选定某一行
update student set name='田七' where code=4 --wheres筛选修改 一个控制条件
go
select *from student
select *from tongxunlu where name='张三'--查询
go
update student set name='飞船',code=5,degree=99 where name='田七'
delete from student --删除所有数据
delete from student where code=3 --删除code=3的一行
drop table student --删除表
--主键 起唯一识别的作用 提高查询效率
create table teacher
(
tno int primary key identity(1,1),--自增长主键
tname varchar(50)
)
--查询
--select *from 表 where 列名 and 列名
create table xinxibiao
(
no int primary key identity(1,1),--自增主键
name varchar(50) not null,
sex varchar(50) not null,
age int not null,
high int not null,
tz decimal(18,2)not null,
sfzh varchar(max)not null,
zhuzhi varchar(max)not null
)
insert into xinxibiao values('洪一','男',50,160,60,'370012598632152233','香港')
select *from xinxibiao
select *from xinxibiao where high>163 and sex='男'
update xinxibiao set name='张初' where name='范大'
--between and 在什么和什么之间
select *from xinxibiao where high between 165 and 175
select *from xinxibiao where name like '李%'--查询表中姓李的
--% 是通配符 可以代替任意字符和数据 like好像的意思