---创建数据库
create database MyDatabase
on primary
(
--名字
name='MyDatabase_0622',
--路径
filename='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDatabase_0622.mdf',
--大小
size=3mb,
--增长
filegrowth=1mb
)
log on
(
--名字
name='MyDatabase_log0622',
--路径
filename='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDatabase_log0622.ldf',
--大小
size=1mb,
--增长
filegrowth=10%
)
---创建表
create table Class
(
ClassID int identity(1,1) primary key,
ClassName nvarchar(10),
ClassDesc nvarchar(20)
)
select *from class --查找一下
------例程创建一个餐桌表
--主键
--餐桌编号
--餐桌的描述信息
--餐桌的备注
--标识 0--空闲 1--使用 2--预定
--餐桌的创建时间
create table DeskInfo
(
DeskId int identity(1,1) primary key,
DeskNumber nvarchar(10),
DeskDesc nvarchar(10),
DeskRemark nvarchar(10),
Flag int,
EeskStartDataTime datetime
)
select *from DeskInfo --查找一下
---通过代码添加数据
--第一种
--insert into 表名(列名,..,列名) values(值,..,值)
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(01,'4人桌','靠窗',0,'2017-6-22')
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(02,'4人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(03,'8人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(04,'8人桌','靠窗',0,'2017-6-22')
select *from DeskInfo
--第二种
--insert into 表名 values(值)
insert into DeskInfo values(01,'4人桌','靠窗',0,'2017-6-22')
insert into DeskInfo values(02,'4人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo values(03,'8人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo values(04,'8人桌','靠窗',0,'2017-6-22')
select *from DeskInfo
--第三种--一次性插入多条数据
--insert into 表名(列名,..,列名)
--select 值,..,值 union
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime)
select 11,'4人桌','靠窗',0,'2017-6-22' union
select 12,'4人桌','靠窗',0,'2017-6-22' union
select 13,'4人桌','靠窗',0,'2017-6-22' union
select 14,'4人桌','靠窗',0,'2017-6-22'
select *from DeskInfo
---修改数据
--updata 表名 set 列=值,列=值 where 条件
update DeskInfo set DeskRemark='靠窗'---无条件时,都更改
select *from DeskInfo
update DeskInfo set DeskRemark='不靠窗' where DeskNumber>=3
select *from DeskInfo
---删除数据
---第一种,表没了,数据也没了
---drop table 表名
---第二种,数据没了,表还在,但是ID号会被删掉,
delete from DeskInfo where DeskNumber=3
select *from DeskInfo
---第三种,数据没了,表还在
truncate table DeskInfo
select *from DeskInfo
create database MyDatabase
on primary
(
--名字
name='MyDatabase_0622',
--路径
filename='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDatabase_0622.mdf',
--大小
size=3mb,
--增长
filegrowth=1mb
)
log on
(
--名字
name='MyDatabase_log0622',
--路径
filename='C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDatabase_log0622.ldf',
--大小
size=1mb,
--增长
filegrowth=10%
)
---创建表
create table Class
(
ClassID int identity(1,1) primary key,
ClassName nvarchar(10),
ClassDesc nvarchar(20)
)
select *from class --查找一下
------例程创建一个餐桌表
--主键
--餐桌编号
--餐桌的描述信息
--餐桌的备注
--标识 0--空闲 1--使用 2--预定
--餐桌的创建时间
create table DeskInfo
(
DeskId int identity(1,1) primary key,
DeskNumber nvarchar(10),
DeskDesc nvarchar(10),
DeskRemark nvarchar(10),
Flag int,
EeskStartDataTime datetime
)
select *from DeskInfo --查找一下
---通过代码添加数据
--第一种
--insert into 表名(列名,..,列名) values(值,..,值)
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(01,'4人桌','靠窗',0,'2017-6-22')
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(02,'4人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(03,'8人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime) values(04,'8人桌','靠窗',0,'2017-6-22')
select *from DeskInfo
--第二种
--insert into 表名 values(值)
insert into DeskInfo values(01,'4人桌','靠窗',0,'2017-6-22')
insert into DeskInfo values(02,'4人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo values(03,'8人桌','不靠窗',0,'2017-6-22')
insert into DeskInfo values(04,'8人桌','靠窗',0,'2017-6-22')
select *from DeskInfo
--第三种--一次性插入多条数据
--insert into 表名(列名,..,列名)
--select 值,..,值 union
insert into DeskInfo(DeskNumber,DeskDesc,DeskRemark,Flag,EeskStartDataTime)
select 11,'4人桌','靠窗',0,'2017-6-22' union
select 12,'4人桌','靠窗',0,'2017-6-22' union
select 13,'4人桌','靠窗',0,'2017-6-22' union
select 14,'4人桌','靠窗',0,'2017-6-22'
select *from DeskInfo
---修改数据
--updata 表名 set 列=值,列=值 where 条件
update DeskInfo set DeskRemark='靠窗'---无条件时,都更改
select *from DeskInfo
update DeskInfo set DeskRemark='不靠窗' where DeskNumber>=3
select *from DeskInfo
---删除数据
---第一种,表没了,数据也没了
---drop table 表名
---第二种,数据没了,表还在,但是ID号会被删掉,
delete from DeskInfo where DeskNumber=3
select *from DeskInfo
---第三种,数据没了,表还在
truncate table DeskInfo
select *from DeskInfo