//xp创建指令
exec xp_cmdshell 'mkdir D:\\DB'
//如果系统存在此对象的数据库 删除
if exists(select * from sysdatabases where name = 'StuDB')
drop database StuDB
//创建数据库StuDB
//数据库名字,文件路径,文件大小,文件最大空间,增长速度
create database StuDB
on
(
name = 'StuDB_main_db',
filename = 'D:\DB\StuDB_main.mdf',
size = 10mb,
maxsize = 20mb,
filegrowth = 10%
)
log on
(
name = 'StuDB_log_db',
filename = 'D:\DB\StuDB_log.ldf',
size = 10mb,
maxsize = 20mb,
filegrowth = 10%
)
use StuDB
//如果系统存在此对象的表 删除
if exists(select * from sysobjects where name = 'student')
drop table student
create table student
(
sid int identity(10001001,1) primary key,
sname varchar(40),
age int,
* varchar(20)
)
select * from student
//插入数据
insert into student values('张三',22,'男')
delete from student where sid = 10001005
insert into student values(10001006,'李四',22,'男')
insert into student values(10001006,'李四',22,'男')
set identity_insert student on
insert into student(sid,sname,age,*) values(10001006,'李四',22,'男')
insert into student(sid,sname,age,*) values(10001010,'李四',22,'男')
insert into student(sid,sname,age,*) values(10001011,'李四',22,'男')
//删除
delete from student where sid = 10001005
delete from student where sid = 10001006
delete from student where sid = 10001010
delete from student where sid = 10001011
delete from student where sid = 10001007
select * from student
//数据库基本用法