日期:2014-05-18  浏览次数:20597 次

创建数据库库错误求解?
use master
go

if exists(select * from sys.databases where name ='test')
drop database test
create database test
on
(
name='test',
filename='E:\test.mdf',
size=5mb,
filegrowth=10%,
maxsize=50mb
)
log on
(
name='test_log',
filename='E:\test_log.ldf',
size=2mb,
filegrowth=10%,
maxsize=20mb
)

go
use test

if exists (select * from sys.objects where name='users')
drop table users

create table users
(
uid int identity(1,1) primary key,
loginname varchar(20) not null ,
pwd varchar(50) not null
)


if exists (select * from sys.objects where name='users')
drop table userInfo

create table userInfo(
id int identity(1,1) primary key ,
uid int not null,
age int not null,
address varchar(100) not null,
emile varchar(50)
)
insert into users (loginname,pwd)
select 'dsdsds','fsfsfosil' union
select 'dsdsdssdf','fsfkulsfs' union
select 'dsdsdfgdgs','fsfuiuyksfs' union
select 'dsdsdgdgs','fsfsyjfs' union
select 'dsdsddgds','fsjfsfs' union
select 'dsdgdsds','fsgdgfsfs' union
select 'dsdgdgsds','kljklklkl'
insert into userInfo (uid,age,address,emile)
select '1','12','dsdsds','fsfsfosil@126.com' union
select '2','12','dsdsds','fsfsfosil@126.com' union
select '3','12','dsdsds','fsfsfosil@126.com' union
select '4','12','dsdsds','fsfsfosil@126.com' union
select '5','12','dsdsds','fsfsfosil@126.com' union
select '6','12','dsdsds','fsfsfosil@126.com' union
select '8','12','dsdsds','fsfsfosil@126.com' union
select '7','12','dsdsds','fsfsfosil@126.com' union
select '9','12','dsdsds','fsfsfosil@126.com' union
select '11','12','dsdsds','fsfsfosil@126.com' union
select '12','12','dsdsds','fsfsfosil@126.com' union
select '3','12','dsdsds','fsfsfosil@126.com' union
select '1','12','dsdsds','fsfsfosil@126.com'

消息 3701,级别 11,状态 5,第 15 行
无法对 表'userInfo' 执行 删除,因为它不存在,或者您没有所需的权限。

------解决方案--------------------
if exists (select * from sys.objects where name='userInfo')
drop table userInfo


------解决方案--------------------
if exists (select * from sys.objects where name='users')
drop table userInfo

-->

if exists (select * from sys.objects where name='userInfo')
drop table userInfo


------解决方案--------------------
create table userInfo(
id int identity(1,1) primary key ,
uid int not null,
age int not null,
address varchar(100) not null,
emile varchar(50)
)

之后添加一个GO试试