Ylbtech-recode (record)-Database design

Source: Internet
Author: User
Tags recode

Ylbtech-dbs:ylbtech-recode (record)-Database design

-- =============================================
--Databasename:recode
--desc: Record (Life record)
--Creative ideas: History cannot be modified, but can be amended to trace the evolution process.
--pubdate:16:46 2015/1/12
--Author:ylbtech
-- =============================================

1.A, Database diagram (db Diagram) back to top

1.B, database design script back to top

1.b.1,

-- =============================================--Databasename:recode--desc: Record (Life record)--Creative Ideas: History cannot be modified, but can be amended to trace the evolution process. --pubdate:16:46 2015/1/12--Author:ylbtech-- ============================================= UseMasterGO--Drop The database if it already existsIF  EXISTS (    SELECTname fromsys.databasesWHEREName=N'Recode')DROP DATABASERecodeGOCREATE DATABASERecodeGo UseRecodeGO-- =============================================--ylb: Category table--desc:-- =============================================Create TableCategory (CategoryIduniqueidentifier Primary Key,--numberingCategoryNamevarchar( $),--categoryFlagvisiblebit            --is enabled)GoGo-- =============================================--opt:1, adding categories-- =============================================--INSERT INTO Category (categoryid,categoryname,flagvisible) VALUES (', ' Uncategorized ', 0)Go-- =============================================--opt:1, view the list of categories-- =============================================SelectCategoryid,categoryname,flagvisible fromCategoryOrder  byCategoryNameGo-- =============================================--ylb: Record table--desc: Record, record version history--2) Allow only one level of records to be modified, no history changes allowed-- =============================================Create TableRecode (Recodeidint Identity(1,1)Primary Key,--numberingContentvarchar( -),--contentpubdatedatetime default(getdate()),--Release dateEndeditdatedatetime,--Last Modified DateFlagbaseint,--0: Level One: Other level two (i.e. parent unit number)CategoryIduniqueidentifier ReferencesCategory (CATEGORYID)--category number "FK")Go-- =============================================--opt:1, adding records-- =============================================--INSERT INTO Recode (Content,pubdate,flagbase,categoryid) VALUES (' Hi, Rain ', ' 2015-1-12 ', 0, ')Go-- =============================================--Opt:2, modify the record and add notes (modify the original record content, update the last modified date, and insert the modified notes)-- =============================================--Update Recode set content= ' Hi,gr rain ', Endeditdate=getdate () where recode= ' 101 'Go--INSERT INTO Recode (Content,pubdate,flagbase,categoryid) VALUES (' Hi, Rain ', ' 2015-1-12 ', 101, ')Go-- =============================================--Opt:3, List of records-- =============================================SelectRecodeid,content,pubdate,endeditdate,flagbase,categoryid fromRecodewhereFlagbase=0Order  byRecodeidGo-- =============================================--opt:3.2, Record modification notes list-- =============================================SelectRecodeid,content,pubdate,endeditdate,flagbase,categoryid fromRecodewhereFlagbase=101Order  byRecodeid
View Code

1.b.2,

1.C, functional implementation code (function implementation codes) back to top

Ylbtech
Source: http://ylbtech.cnblogs.com/
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Ylbtech-recode (record)-Database design

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.