Use the SQL Server 2000 query analyzer to create tables, insert data, and create triggers

Source: Internet
Author: User

Create Database book

Use book

Create Table personlike
(
Id int primary key,
Likecontent varchar (100) not null
)

Insert into personlike values (1, 'Sports ')
Insert into personlike values (2, 'travel ')
Insert into personlike values (3, 'game ')
Insert into personlike values (4, 'Surfing net ')
Insert into personlike values (5, 'dating ')
Insert into personlike values (6, 'cine ')
Insert into personlike values (7, 'shopping ')
Insert into personlike values (8, 'lobby ')
Insert into personlike values (9 ,'Program')
Insert into personlike values (10, 'assemblies ')

Create Table vote
(
Voteid int primary key,
Voteitem varchar (100) not null,
Votenum int default 0
)

Insert into vote values (1, 'wei Gaofeng ', 0)
Insert into vote values (2, 'taobao', 0)
Insert into vote values (3, 'alizhan fei', 0)

Use vote

Delete table votemaster

Use book

Create Table votemaster
(
Voteid int primary key,
Votetitle varchar (150) not null,
Votesum int default 0
)
Insert into votemaster values (1, 'election of the meeting Chairman! ', 0)
Insert into votemaster values (2, 'comments on website construction! ', 0)

Select * From votemaster

Create Table votedetails
(
-- Id int identity (1, 1) primary key, -- auto-Increment
Voteid int foreign key references votemaster (voteid ),
Votedetailsid int not null,
Voteitem varchar (20) not null,
Votenum int default 0
Primary Key (voteid, votedetailsid)
)
Insert into votedetails values (1, 1, 'wei shout', 0)
Insert into votedetails values (1, 2, 'alizhan fei', 0)
Insert into votedetails values (1, 3, 'valley source', 0)

Insert into votedetails values (, 'Very good', 0)
Insert into votedetails values (2, 2, 'hao', 0)
Insert into votedetails values (2, 3, 'General ', 0)
Insert into votedetails values (2, 4, 'to be improved', 0)

Select * From votedetails

-- Create a trigger
Create trigger updatemaster
On votedetails
For update
As
Begin
Update votemaster set votesum = votesum + 1 where voteid = (select top 1 voteid from inserted)
End
-- Use a subquery to make voteid = the ID of the newly inserted record

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.