sqlserver的学习成长之路,每一个技术的学习过程都是值得让人回味的,现在百度上关于sqlser的资料很多,但是都太杂,希望能为大家分享一点简单易懂的干货,跟大家一起进步学习。

 一、建表

    1、创建表stu_paper(各种常用的类型的字段都有)

IF NOT EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME = 'stu_paper' AND TYPE = 'U')
    BEGIN
    --问卷表
    CREATE TABLE stu_paper(
        P_ID int IDENTITY(1,1) primary key NOT NULL,
        TITLE VARCHAR(200) default '' NOT NULL,                  
        START_TIME datetime default getdate() NOT NULL,   
        SHOW_CONTENT int default 0 NOT NULL,             
        USER_NUM bigint default 0  NOT NULL,         
        FLAG int default 0 NOT NULL ,             
        NTAG1 numeric(10,4),
    )
    END
    GO

   2、创建表stu

IF NOT EXISTS (SELECT * FROM SYSOBJECTS WHERE NAME = 'stu' AND TYPE = 'U')
    BEGIN
    --问卷表
    CREATE TABLE stu(
        P_ID int IDENTITY(1,1) primary key NOT NULL,
        TITLE VARCHAR(200) default '' NOT NULL,                  
        START_TIME datetime default getdate() NOT NULL,   
        SHOW_CONTENT int default 0 NOT NULL,             
        USER_NUM bigint default 0  NOT NULL,         
        FLAG int default 0 NOT NULL ,             
        NTAG1 numeric(10,4),
    )
    END
    GO

二、为表stu_paper增加字段

1 alter table dbo.stu_paper add age int default 0 not null;
2 alter table dbo.stu_paper add name VARCHAR(200) default '' not null;

三、修改表stu_paper中的字段name 的长度为varchar(256)

1 alter table stu_paper  alter column name varchar(256);

四、存储过程

  1、创建存储过程,将将表stu_paper中数据同步到表stu中

1 CREATE PROC [DBO].[PRO_STUPAPER]
2 AS
3 IF EXISTS(SELECT COUNT(*) FROM DBO.stu_paper)
4 BEGIN
5     DELETE FROM DBO.stu_paper;
6     INSERT INTO DBO.stu(TITLE,START_TIME,SHOW_CONTENT,USER_NUM,FLAG,NTAG1)
7             SELECT TITLE,START_TIME,SHOW_CONTENT,USER_NUM,FLAG,NTAG1 FROM DBO.stu_paper;
8 END
9 GO

  2、执行存储过程

1 EXEC DBO.PRO_STUPAPER
2 GO

五、sqlserver定时任务

  1、创建定时任务(即作业)

    参考网址:https://jingyan.baidu.com/article/b907e62790e89846e7891cc4.html?qq-pf-to=pcqq.c2c

   2、查看定时任务日志

    参考网址:https://jingyan.baidu.com/article/0f5fb099efaa2c6d8334eae5.html?qq-pf-to=pcqq.c2c

 

 

 

 

 

 

 

 

  

版权声明:本文为ouyy原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/ouyy/p/8715560.html