SQL Server Learning _01

Source: Internet
Author: User
Tags getdate

SQL Server learning and growth path, each technology learning process is worth to be memorable, and now Baidu on the sqlser on a lot of information, but are too miscellaneous, I hope to share a little easy to understand the dry, with everyone to improve learning.

I. Establishment of the table

1, create the table stu_paper (various common types of fields are available)

IF not EXISTS (SELECT * from SYSOBJECTS WHERE NAME ='Stu_paper'and TYPE ='U') BEGIN--Questionnaire CREATE Table Stu_paper (p_idintIDENTITY (1,1) primary key not NULL, TITLE VARCHAR ( $)default "'Not NULL, start_time datetimedefaultgetdate () not NULL, Show_contentint default 0Not NULL, user_num bigintdefault 0Not NULL, FLAGint default 0Not NULL, NTAG1 numeric (Ten,4),) END GO

2. CREATE TABLE Stu

IF not EXISTS (SELECT * from SYSOBJECTS WHERE NAME ='Stu'and TYPE ='U') BEGIN--Questionnaire CREATE Table Stu (p_idintIDENTITY (1,1) primary key not NULL, TITLE VARCHAR ( $)default "'Not NULL, start_time datetimedefaultgetdate () not NULL, Show_contentint default 0Not NULL, user_num bigintdefault 0Not NULL, FLAGint default 0Not NULL, NTAG1 numeric (Ten,4),) END GO

Ii. Add fields for table Stu_paper

1 int default 0 NULL ; 2 ALTER TABLE Dbo.stu_paper add name VARCHAR ($default'null;

Third, modify the field in table stu_paper the length of name is varchar (256)

1 ALTER TABLE Stu_paper  ALTER column name varchar (n);

Iv. Stored Procedures

1. Create a stored procedure to synchronize the data in the table Stu_paper to the table Stu

1 CREATE PROC [DBO]. [Pro_stupaper] 2  as 3 IF EXISTS (SELECT COUNT (*) from Dbo.stu_paper)4BEGIN5    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. Execute Stored Procedure

1 EXEC Dbo.pro_stupaper 2 GO

V. SQL Server timed Tasks

1. Create timed tasks (i.e. jobs)

Reference URL: https://jingyan.baidu.com/article/b907e62790e89846e7891cc4.html?qq-pf-to=pcqq.c2c

2. Check the Scheduled task log

Reference URL: https://jingyan.baidu.com/article/0f5fb099efaa2c6d8334eae5.html?qq-pf-to=pcqq.c2c

  

SQL Server Learning _01

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.