From 1405693261c09dd658423c30803845bb63050141 Mon Sep 17 00:00:00 2001 From: lsy2246 Date: Tue, 14 May 2024 12:11:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SQL_SERVER/.vs/Solution1/v15/.ssms_suo | Bin 0 -> 16384 bytes SQL_SERVER/Chat.sql | 102 +++++++++++++++++++++++++ SQL_SERVER/bank.sql | 42 ++++++++++ 3 files changed, 144 insertions(+) create mode 100644 SQL_SERVER/.vs/Solution1/v15/.ssms_suo create mode 100644 SQL_SERVER/Chat.sql create mode 100644 SQL_SERVER/bank.sql diff --git a/SQL_SERVER/.vs/Solution1/v15/.ssms_suo b/SQL_SERVER/.vs/Solution1/v15/.ssms_suo new file mode 100644 index 0000000000000000000000000000000000000000..83817f852d439070aebb646b091426d891c25d45 GIT binary patch literal 16384 zcmeHO%Xd>n7@vSh!3S0p6;Yxf7VQmr^~po>JaDA+k+yIY4<~KX5=fJhq(D#8g)8+x zaH($Gd5&(}>&g|#!i6hXdyY$YQh&d>cbc2qJZ_TGhs~EWcjnH_o!>ma`Mz%^5AJt9 z`u4}ekA;QKiQVGK%0BU|Dc*tbF7^JB5YHgYxF;(sD~#R^hhUqwQ4frXEPe&y6cLeu zpA(B5O51cu>{%W2Lv_A#?s<6jqs*U*g% zxYyy{fa88o{?ELM{~yJ>6Yd?jcj1n~9fx}l?gZTXaLj+w@D&byml5Z#kcQ+oHP8b= zNIY3_OUyyq$-%cP_n_+~9fABo9YC#TBf6&7jnpn9$2f5Fz`X=nCl5&|CT>U>tRSYP zWR$O266ee=2lbUHKw3vc_4>h3tcL(*Et}Fd!)+K{_CD1Q9q|PB+YCG$p@X1H);`2L>7imb0i3#DvsAtjdl*LoBtxnTO z=s7DtPc$L_pF&YnMsYEW?zA!1oO1~|3a&NvabbmI(E|xN6Bf`b1zEy5;8PBF!r5)V z2YJ=}w~jyOUj``b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jx>Js;TYcA}_5me;GJNvqMY%rIBZwGH)}sgIvL-!X$X~;Tg4! z%6U~@Gu0#dop9E$L;hQ039VnRx}8QJ39+6fx-cF|{JS%5jI#@2+WmRQ{{})lZ7}yX z^^*Y7c-nslUxtu>R_5rCYpuMrqNViH$Z4NwhdPMt4)M7oJm|)6Dd3Gp`uq`(7VPu; zG><3j)&dbv09Mj~J2c>qMx!C$a`DViDnA`frIYz{#kz+s#id|RpvT=C38K7UMDzFc zd$oapr(g4WyuCdkZz$jn`j^Q<$R$Xr^IM`q;Vn>$$+Ck1r{)YtVjqtWk7)i8uY1TH z<_)*V)seACEasYv=L^Z4v&)(#keEwlQu#tIUdST3$A9uI4NycY<1O8;v*E`^Xb-v%*Th!-=`AH#;7qFY4{{V!Nj6eVY literal 0 HcmV?d00001 diff --git a/SQL_SERVER/Chat.sql b/SQL_SERVER/Chat.sql new file mode 100644 index 0000000..8c4389c --- /dev/null +++ b/SQL_SERVER/Chat.sql @@ -0,0 +1,102 @@ +CREATE LOGIN Chat + WITH PASSWORD = '123456'; +GO + +DROP DATABASE Chat; +GO + +CREATE DATABASE Chat; +GO + +USE Chat; +GO + +CREATE USER Chat + FOR LOGIN Chat; +GO + +ALTER ROLE db_owner ADD MEMBER Chat; +GO + +CREATE TABLE Account +( + Id BIGINT PRIMARY KEY IDENTITY(1000,1), + Password VARCHAR(50) not null, + NetName NVARCHAR(50) , + State BIT default 0 CHECK(State=1 or State=0), + UpDataTime datetime default GETDATE() +) +GO + +CREATE TABLE Contacts +( + UserId BIGINT REFERENCES Account(Id) not null , + ContactsId BIGINT REFERENCES Account(Id) not null, + State BIT default 0 CHECK(State=1 or State=0), + Remark NVARCHAR(50), + UpDataTime datetime default GETDATE() +) +GO + +CREATE TABLE History +( + Send BIGINT REFERENCES Account(Id) NOT NULL, + Receive BIGINT REFERENCES Account(Id) NOT NULL, + Type NVARCHAR(50) NOT NULL, + Content NVARCHAR(200) NOT NULL, + Time DATETIME DEFAULT GETDATE() +) + +GO + +-- Account表的更新触发器 +CREATE TRIGGER trg_UpdateUpDataTimeAccount +ON Account +AFTER INSERT, UPDATE, DELETE +AS +BEGIN + SET NOCOUNT ON; + UPDATE Account + SET UpDataTime = GETDATE() + WHERE Id IN (SELECT Id FROM inserted UNION SELECT Id FROM deleted); +END; +GO + + +-- Contacts表的更新触发器 +CREATE TRIGGER trg_UpdateUpDataTimeContacts +ON Contacts +AFTER INSERT, UPDATE +AS +BEGIN + SET NOCOUNT ON; + + -- 更新Account表中的UpDataTime字段,仅在Contacts相关记录发生插入或更新时 + UPDATE Account + SET UpDataTime = GETDATE() + WHERE Id IN (SELECT UserId FROM inserted) + OR Id IN (SELECT ContactsId FROM inserted); + + -- 更新Contacts表的Remark列为对应ContactsId的NetName + UPDATE Contacts + SET Remark = (SELECT NetName FROM Account WHERE Id = ContactsId) + WHERE ContactsId IN (SELECT ContactsId FROM inserted) + OR ContactsId IN (SELECT ContactsId FROM deleted); +END; +GO + +-- History表的更新触发器 +CREATE TRIGGER trg_UpdateUpDataTimeHistory +ON History +AFTER INSERT, UPDATE +AS +BEGIN + SET NOCOUNT ON; + + -- 仅更新Account表中发送者和接收者的UpDataTime字段 + UPDATE Account + SET UpDataTime = GETDATE() + WHERE Id IN (SELECT Send FROM inserted) + OR Id IN (SELECT Receive FROM inserted); +END; +GO diff --git a/SQL_SERVER/bank.sql b/SQL_SERVER/bank.sql new file mode 100644 index 0000000..4d8c9fa --- /dev/null +++ b/SQL_SERVER/bank.sql @@ -0,0 +1,42 @@ +CREATE DATABASE BANKSYSTEM; + +USE BANKSYSTEM; + +CREATE TABLE AccountInfo +( + AccountId INT PRIMARY KEY IDENTITY (1,1), + NetName NVARCHAR(50) NOT NULL, + Password NVARCHAR(50) NOT NULL, + Name NVARCHAR(5) NOT NULL, + IdCard VARCHAR(18) UNIQUE NOT NULL, + OpenTime datetime default getdate() +) + +CREATE TABLE State +( + StateId INT PRIMARY KEY, + Name VARCHAR(50) unique not null +) + + +CREATE TABLE BankCard +( + Id VARCHAR(18) PRIMARY KEY, + Password VARCHAR(6) NOT NULL, + Money money default 0 check (Money >= 0), + OpenTime smalldatetime default getdate(), + AccountId INT REFERENCES AccountInfo (AccountId), + StateId INT REFERENCES State (StateId) DEFAULT 1, + WhyState NVARCHAR(50) +) + +CREATE TABLE Bill +( + Id INT PRIMARY KEY IDENTITY (1,1), + BankId VARCHAR(18) REFERENCES BankCard (Id) NOT NULL, + Money money default 0, + Source VARCHAR(50) NOT NULL, + Mod VARCHAR(10) NOT NULL CHECK (Mod = 'Input' OR Mod = 'Output'), + State VARCHAR(10) NOT NULL CHECK (State = 'True' or State = 'False'), + Time datetime default getdate() +)