要求:
1、用SQL语句建立一个ShopDB
2、用SQL语句对其进行增、删、改、查
要求:
1、用SQL语句建立一个ShopDB
2、用SQL语句对其进行增、删、改、查
Use master
Go
If Exists (select * from sysdataBases where name = 'ShopDB')
Drop dataBase ShopDB
Go
Create DataBase ShopDB
On
Primary
(
Name = 'ShopDB',
FileName = 'E:\ShopDB_data.mdf',
Size = 10MB,
FileGrowth = 20%
)
Log On
(
Name = 'ShopDB2',
FileName = 'E:\ShopDB_log.ldf',
Size = 3MB,
MaxSize = 20MB,
FileGrowth = 10%
)
Go
Use ShopDB
Go
If Exists (select * from sysObjects where name = 'Users')
Drop table Users
Go
Create Table Users
(
ID int Identity (1,1) not null ,
myname varchar (15) not null ,
age int
)
Go
---------插入数据-----------
insert into Users values ('雨',18)
insert into Users values ('叶',21)
insert into Users values ('露',24)
select * from users
If Exists ( select * from sysobjects where name = 'proc_select')
Drop procedure proc_select
Go
Create procedure proc_select
As
Select age,myname from Users where age > 18
Go
Exec proc_select
Go
If Exists ( select * from sysobjects where name = 'proc_insert')
Drop procedure proc_insert
Go
Create procedure proc_insert
@userName varchar(20),
@age int
As
insert into Users values (@userName,@age)
Go
Exec proc_insert sky,20
Go
If Exists ( select * from sysobjects where name = 'proc_update')
Drop procedure proc_insert
Go
Create procedure proc_update
@userName varchar(20),
@age Money
As
update Users set age=@age where myname = @userName
Go
Exec proc_update sky,21
Go
If Exists ( select * from sysobjects where name = 'proc_delete')
Drop procedure proc_delete
Go
Create procedure proc_delete
@userName varchar(20)
As
delete from Users where myName = @userName
Go
Exec proc_delete sky
Go