课后作业
作业1:创建一个新的数据库,名称为homework。使用自定义参数形式来创建,参数大小自己决定。
create database homework on primary(
name=homework,
filename="E:\SQL\homework.mdf",
size=5MB,
filegrowth=5MB,
maxsize=100MB
)log on(
name=homework_log,
filename="E:\SQL\homework_log.ldf",
size=5MB,
filegrowth=5MB,
maxsize=100MB);
作业2:按下表数据,在homework数据库下创建user_profile表,id列是主键列。并插入对应数据。将写好的建表语句和数据插入语句代码返回。
建表语句:
use homework;
create table user_profile(
id int primary key,
device_id int,
gender varchar,
age int,
university nvarchar,
province varchar
);
数据插入语句:
insert into user_profile values(1,2138,'male',21,'北京大学','Beijing');
insert into user_profile values(2,3214,'male',null,'复旦大学','Shanghai');
insert into user_profile values(3,6543,'female',20,'北京大学','Beijing');
insert into user_profile values(4,2315,'female',23,'浙江大学','Zhejiang');
insert into user_profile values(5,5432,'male',25,'山东大学','Shandong');
作业3:查询user_profile表的所有数据。
查询语句:
select * from user_profile;
作业4:查询user_profile表中年龄大于22岁男性数据的大学信息。
查询语句:
select university from user_profile where age>22 and gender='male';