心悦琴
2021-04-06 17:21
采纳率: 97.4%
浏览 184

数据库“test”的事务日志已满,原因为“ACTIVE_TRANSACTION”。求助

--判断数据库test是否已经存在,若不存在则重新创建一个数据库,若存在则保留
IF (NOT EXISTS(SELECT * FROM master.dbo.sysdatabases WHERE dbid=db_ID('test')))
BEGIN
---创建数据库
CREATE DATABASE test
ON
PRIMARY(NAME=test_Data,filename='D:\data\test_Data.mdf',Size=8MB,maxsize=20MB,fileGrowth=1MB),
(NAME=test_Data_1,
filename='D:\data\test_Data1.ndf',size=1MB,maxsize=20MB,filegrowth=2MB),
(NAME=test_Data_2,filename='D:\data\test_Data2.ndf',size=2MB,maxsize=20MB,filegrowth=2MB)
Log on
(NAME=test_Log,filename='D:\data\test_Log.ldf',size=1MB,maxsize=20MB,filegrowth=10%)
END 


if not exists ( select name from sysobjects where name='PART' and type='U' )
begin
CREATE TABLE PART
(P_PARTKEY int primary key,
P_NAME varchar(55),
P_MFGR char(25),
P_BRAND char(10),
P_TYPE varchar(25),
P_SIZE int,
P_CONTAINER char(10),
P_RETAILPRICE decimal,
P_COMMENT varchar(23))
end
TRUNCATE TABLE PART;  ---清空表格里的数据
BULK INSERT PART ---插入表格里的数据
FROM"D:\qq文件\TCPH dataset-1G\part.csv"
WITH
(FIELDTERMINATOR=',',    ---列分隔符
ROWTERMINATOR='\n')        ---行分隔符

if not exists (select name from sysobjects where name='supplier' and type='U' )
begin
CREATE TABLE SUPPLIER
(S_SUPPKEY int PRIMARY KEY,
S_NAME char(25),
S_ADDRESS varchar(40),
S_NATIONKEY INT FOREIGN KEY REFERENCES NATION(N_NATIONKEY),
S_PHONE CHAR(15),
S_ACCTBAL DECIMAL,
S_COMMENT VARCHAR(101))
end
TRUNCATE TABLE SUPPLIER;
BULK INSERT SUPPLIER
FROM"D:\qq文件\TCPH dataset-1G\supplier.csv"
WITH
(FIELDTERMINATOR=',',
ROWTERMINATOR='\n')


if not exists ( select name from sysobjects where name='region' and type='U' )
begin
CREATE TABLE REGION
(R_REGIONKEY INT PRIMARY KEY,
R_NAME CHAR(25),
R_COMMENT VARCHAR(152))
end
TRUNCATE TABLE REGION;
BULK INSERT REGION
FROM"D:\qq文件\TCPH dataset-1G\region.csv"
WITH
(FIELDTERMINATOR=',',
ROWTERMINATOR='\n')


if not exists ( select name from sysobjects where name='nation' and type='U' )
begin
CREATE TABLE NATION
(N_NATIONKEY INT PRIMARY KEY,
N_NAME CHAR(25),
N_REGIONKEY INT FOREIGN KEY REFERENCES REGION(R_REGIONKEY),
N_COMMENT VARCHAR(152))
end
TRUNCATE TABLE NATION;
BULK INSERT NATION
FROM"D:\qq文件\TCPH dataset-1G\nation.csv"
WITH
(FIELDTERMINATOR=',',
ROWTERMINATOR='\n')



if not exists ( select name from sysobjects where name='partsupp' and type='U' )
begin
CREATE TABLE PARTSUPP
(PS_PARTKEY INT FOREIGN KEY REFERENCES PART(P_PARTKEY),
PS_SUPPKEY INT FOREIGN KEY REFERENCES SUPPLIER(S_SUPPKEY),
PS_AVAILQTY INT,
PS_SUPPLYCOST DECIMAL,
PS_COMMENT VARCHAR(199),
PRIMARY KEY(PS_PARTKEY,PS_SUPPKEY))
end
TRUNCATE TABLE PARTSUPP;
BULK INSERT PARTSUPP
FROM"D:\qq文件\TCPH dataset-1G\partsupp.csv"
WITH
(FIELDTERMINATOR=',',
ROWTERMINATOR='\n')




--drop table NATION
--drop table REGION
--drop table PART
--drop table PARTSUPP
--drop table SUPPLIER

消息 9002,级别 17,状态 4,第 16 行
数据库“test”的事务日志已满,原因为“ACTIVE_TRANSACTION”。
参考过这个链接,但是发现没有用,望不吝赐教。

https://developer.aliyun.com/article/362287

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

相关推荐 更多相似问题