用 CREATE TABLE 命令建立表的结构

 创建一个水果表fruit
列名分别为:
code (int)
name (varchar(50)) not null
price  (decimal(18,2)) not null
address (varchar(50)) not null
1)查询全部数据
2)查询一列(name)
3)查询多个列(name、产地)
4)根据条件查询一行(code=2)
5)根据条件查找一个数据(code为2的name)
6)根据条件查找多个数据(code为2的name、price)
7)插入一条数据(自己想)
8)更改code为5的水果的价格为8.5
9)删除code为5的水果的数据

use student
go
create table fruit
(
code int,
name varchar(50)not null,
price decimal(18,2) not null,
address varchar (50) not null
)
go
insert into fruit values (1.,'苹果',1.1,'淄博')
insert into fruit values (2.,'梨',1.3,'北京')
insert into fruit values (3.,'香蕉',3.1,'南京')
insert into fruit values (4.,'橘子',2.1,'武汉')
insert into fruit values (5.,'荔枝',3.4,'扬州')
insert into fruit values (6.,'火龙果',2.4,'杭州')
insert into fruit values (7.,'西瓜',2.8,'潍坊')
go

--1)查询全部数据
select * from fruit

--2)查询一列(name)
select name from fruit


--3)查询多个列(name、产地)
select name,address from fruit


--4)根据条件查询一行(code=2)
select*from fruit where code=2


--5)根据条件查找一个数据(code为2的name)
select name from fruit where code=2


--6)根据条件查找多个数据(code为2的name、price)
select name,price from fruit where code=2

--7)插入一条数据(自己想)
insert into fruit values (8.,'芒果',3.6,'浙江')


--8)更改code为5的水果的价格为8.5
update fruit set price=8.5 where code=5


--9)删除code为5的水果的数据
delete from fruit where code=5

原文地址:https://www.cnblogs.com/dulovexin/p/4972113.html