每天向数据库里添加记录的作业命令怎么写
发布网友
发布时间:2022-04-30 09:55
我来回答
共5个回答
懂视网
时间:2022-04-09 01:39
action;
import dao.C2SDao;
import model.C2S;
import java.sql.SQLException;
import java.util.List;
/**
* Created by yinus
* Date:2016/4/6
* Time:18:43
*/
public class C2SAction {
public void add(C2S c) throws SQLException {
C2SDao cd = new C2SDao();
cd.add(c);
}
public void delete(int id ,boolean isStudentId) throws SQLException {
C2SDao cd = new C2SDao();
cd.delete(id,isStudentId);
}
public void delete(int stuId,int couId) throws SQLException {
C2SDao cd = new C2SDao();
cd.delete(stuId,couId);
}
public void update(C2S c) throws SQLException {
C2SDao cd = new C2SDao();
cd.update(c);
}
public List<C2S> querys(int id, boolean isStudentId) throws SQLException {
C2SDao cd = new C2SDao();
return cd.queryById(id,isStudentId);
}
public C2S query(int stuId,int couId) throws SQLException {
C2SDao cd = new C2SDao();
return cd.queryByStudentIdAndCourseId(stuId,couId);
}
}
package action;
import dao.CourseDao;
import model.Course;
import java.sql.SQLException;
import java.util.List;
/**
* Created by yinus
* Date:2016/4/6
* Time:18:43
*/
public class CourseAction {
public void add(Course course) throws SQLException {
CourseDao courseDao = new CourseDao();
courseDao.addCourse(course);
}
public void update(Course course) throws SQLException {
CourseDao courseDao = new CourseDao();
courseDao.updateCourse(course);
}
public void delete(int id) throws SQLException {
CourseDao courseDao = new CourseDao();
courseDao.delCourse(id);
}
public List<Course> queryByName(String name) throws SQLException {
CourseDao courseDao = new CourseDao();
return courseDao.queryCourses(name);
}
public Course queryById(int id) throws SQLException {
CourseDao courseDao = new CourseDao();
return courseDao.querySingleCourse(id);
}
}
package action;
import dao.StudentDao;
import model.Student;
import java.sql.SQLException;
import java.util.List;
/**
* Created by yinus
* Date:2016/4/6
* Time:18:43
*/
public class StudentAction {
public void add(Student student) throws SQLException {
StudentDao studentDao = new StudentDao();
studentDao.addStudent(student);
}
public void update(Student student) throws SQLException {
StudentDao studentDao = new StudentDao();
studentDao.updateStudent(student);
}
public void delete(int id) throws SQLException {
StudentDao studentDao = new StudentDao();
studentDao.delStudent(id);
}
public List<Student> queryByName(String name) throws SQLException {
StudentDao studentDao = new StudentDao();
return studentDao.queryStudents(name);
}
public Student queryById(int id) throws SQLException {
StudentDao studentDao = new StudentDao();
return studentDao.querySingleStudent(id);
}
}
第二次数据库作业--action
标签:
热心网友
时间:2022-04-08 22:47
-- 2009-05-23/8:43 上生成的脚本
-- 由: XFLIU\Administrator
-- 服务器: (local)
BEGIN TRANSACTION
DECLARE @JobID BINARY(16)
DECLARE @ReturnCode INT
SELECT @ReturnCode = 0
IF (SELECT COUNT(*) FROM msdb.dbo.syscategories WHERE name = N'[Uncategorized (Local)]') < 1
EXECUTE msdb.dbo.sp_add_category @name = N'[Uncategorized (Local)]'
-- 删除同名的警报(如果有的话)。
SELECT @JobID = job_id
FROM msdb.dbo.sysjobs
WHERE (name = N'step1')
IF (@JobID IS NOT NULL)
BEGIN
-- 检查此作业是否为多重服务器作业
IF (EXISTS (SELECT *
FROM msdb.dbo.sysjobservers
WHERE (job_id = @JobID) AND (server_id <> 0)))
BEGIN
-- 已经存在,因而终止脚本
RAISERROR (N'无法导入作业“step1”,因为已经有相同名称的多重服务器作业。', 16, 1)
GOTO QuitWithRollback
END
ELSE
-- 删除〔本地〕作业
EXECUTE msdb.dbo.sp_delete_job @job_name = N'step1'
SELECT @JobID = NULL
END
BEGIN
-- 添加作业
EXECUTE @ReturnCode = msdb.dbo.sp_add_job @job_id = @JobID OUTPUT , @job_name = N'step1', @owner_login_name = N'sa', @description = N'没有可用的描述。', @category_name = N'[Uncategorized (Local)]', @enabled = 1, @notify_level_email = 0, @notify_level_page = 0, @notify_level_netsend = 0, @notify_level_eventlog = 2, @delete_level= 0
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- 添加作业步骤
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobstep @job_id = @JobID, @step_id = 1, @step_name = N'step2', @command = N'insert into B(AID,DATES)
select * from A where A.AID not in (select AID from B)', @database_name = N'仓库信息管理系统', @server = N'', @database_user_name = N'', @subsystem = N'TSQL', @cmdexec_success_code = 0, @flags = 0, @retry_attempts = 0, @retry_interval = 1, @output_file_name = N'', @on_success_step_id = 0, @on_success_action = 1, @on_fail_step_id = 0, @on_fail_action = 2
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
EXECUTE @ReturnCode = msdb.dbo.sp_update_job @job_id = @JobID, @start_step_id = 1
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- 添加作业调度
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobschele @job_id = @JobID, @name = N'step3', @enabled = 1, @freq_type = 4, @active_start_date = 20090523, @active_start_time = 0, @freq_interval = 1, @freq_subday_type = 1, @freq_subday_interval = 0, @freq_relative_interval = 0, @freq_recurrence_factor = 0, @active_end_date = 99991231, @active_end_time = 235959
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
-- 添加目标服务器
EXECUTE @ReturnCode = msdb.dbo.sp_add_jobserver @job_id = @JobID, @server_name = N'(local)'
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
END
COMMIT TRANSACTION
GOTO EndSave
QuitWithRollback:
IF (@@TRANCOUNT > 0) ROLLBACK TRANSACTION
EndSave:
--补充-----------------
把@database_name换成你的数据库名称 @command语句的话要是A和B表的就不用改了,要是是其它的表名就修改下
热心网友
时间:2022-04-09 00:05
其实这个问题很简单的,三点:
1. 关键的语句:insert into B (AID) select AID from A
2. 在B的DATES字段默认为:Convert(Varchar(10),getdate(),120)
3. 直接在数据库的SQL Server代理里面的作业里面新建作业,指定执行时间和
周期,然后在步骤里面加入上面的语句即可。
热心网友
时间:2022-04-09 01:40
涉及到sqlserver定时作业。
你的数据库服务器-》企业管理器-》管理-》SQL Server 代理-》作业-》新建作业,按照要求填就可以了,在“步骤”的“命令”中填写你要执行的存储过程或语句,在“调度”里面填写什么时间执行
具体你可以参考这个网页http://www.net130.com/CMS/Pub/softlevel/softlevel_dbengineer/2006_08_16_35375.htm
热心网友
时间:2022-04-09 03:31
学习