SQL Server:html
-- 建立表 DROP TABLE [t_test_timestamp]; GO CREATE TABLE [dbo].[t_test_timestamp]( [id] [INT] NOT NULL, [name] [VARCHAR](255) NULL, [updated_at] [DATETIME], CONSTRAINT [PK__t_test_t__3213E83F108B795B] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO CREATE TRIGGER [dbo].[Tr_t_test_timestamp_insert] ON [dbo].[t_test_timestamp] after insert AS BEGIN Set Nocount On; /*屏蔽觸發器裏Insert語句執行完後返回的所影響的行數的消息*/ DECLARE mycursor CURSOR local FOR SELECT id FROM inserted DECLARE @id INT OPEN mycursor FETCH NEXT FROM mycursor INTO @id WHILE @@fetch_status = 0 BEGIN UPDATE dbo.t_test_timestamp SET updated_at=GETDATE() WHERE id=@id FETCH NEXT FROM mycursor INTO @id END CLOSE mycursor DEALLOCATE mycursor END GO CREATE TRIGGER [dbo].[Tr_t_test_timestamp_update] ON [dbo].[t_test_timestamp] after update AS BEGIN Set Nocount On; /*屏蔽觸發器裏Insert語句執行完後返回的所影響的行數的消息*/ DECLARE mycursor CURSOR local FOR SELECT id FROM inserted DECLARE @id INT OPEN mycursor FETCH NEXT FROM mycursor INTO @id WHILE @@fetch_status = 0 BEGIN IF NOT UPDATE(updated_at) BEGIN UPDATE dbo.t_test_timestamp SET updated_at=GETDATE() WHERE id=@id END FETCH NEXT FROM mycursor INTO @id END CLOSE mycursor DEALLOCATE mycursor END GO -- 測試插入數據 insert into t_test_timestamp(id,name) values(1,'北京') ; insert into t_test_timestamp(id,name) values(2,'上海') ; SELECT * FROM dbo.t_test_timestamp; -- 測試更新數據 update t_test_timestamp set name='北京2' where id=1; SELECT * FROM dbo.t_test_timestamp;
SqlServer版本的只讀用戶增長辦法:
https://blog.csdn.net/enweitech/article/details/47393657 sql
Oracle版本:數據庫
1)建立表空間oracle
/*分爲四步 */ /*第1步:建立臨時表空間 */ create temporary tablespace yuhang_temp tempfile 'E:\oracledata\yuhang_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local; /*第2步:建立數據表空間 */ create tablespace yuhang_data logging datafile 'E:\oracledata\yuhang_data.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local; /*第3步:建立用戶並指定表空間 */ create user yuhang identified by yuhang default tablespace yuhang_data temporary tablespace yuhang_temp; /*第4步:給用戶授予權限 */ grant connect,resource,dba to yuhang;
2) 建立表與觸發器ide
-- Create table create table T_TEST_TIMESTAMP ( id NUMBER not null, name VARCHAR2(255), updated_at DATE ) tablespace YUHANG_DATA pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table T_TEST_TIMESTAMP add constraint ID primary key (ID) using index tablespace YUHANG_DATA pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited ); create or replace trigger sys.Tr_t_test_timestamp_modify before insert or update on YUHANG.T_TEST_TIMESTAMP for each row declare -- local variables here begin IF INSERTING THEN :NEW.updated_at := SYSDATE; ELSIF UPDATING then :NEW.updated_at := SYSDATE; END IF; end Tr_t_test_timestamp_modify;
3)測試測試
-- 測試插入數據 insert into T_TEST_TIMESTAMP(id,name) values(1,'北京') ; insert into T_TEST_TIMESTAMP(id,name) values(2,'上海') ; commit; SELECT * FROM t_test_timestamp; -- 測試更新數據 update t_test_timestamp set name='北京2' where id=1; commit; SELECT * FROM t_test_timestamp;
Oracle只讀用戶的建立辦法:https://www.cnblogs.com/xinxin1994/p/6290314.html fetch
MYSQL數據庫 大數據
CREATE TABLE `trg_t_test_timestamp_insert` ( `id` int(11) NOT NULL, `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL, `update_time` timestamp(0) NOT NULL DEFAULT current_timestamp() ON UPDATE CURRENT_TIMESTAMP(0), PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic; -- 也能夠採起以下的觸發器方式 -- 建立時間戳觸發器INSERT create trigger `trg_t_test_timestamp_insert` before insert on `t_test_timestamp` for each row set new.update_time = current_time; -- 建立時間戳觸發器UPDATE create trigger `trg_t_test_timestamp_update` before update on `t_test_timestamp` for each row set new.update_time = current_time; insert into `t_test_timestamp`(id,`name`) values(1,'北京') ; insert into `t_test_timestamp`(id,`name`) values(2,'上海') ; select * from `t_test_timestamp`; 1 北京 2018-06-28 15:35:42 2 上海 2018-06-28 15:35:42 update `t_test_timestamp` set `name`='北京2' where id=1; select * from `t_test_timestamp`;
Mysql只讀用戶的建立辦法:https://www.cnblogs.com/sybblogs/p/8796275.htmlspa
關於數據的刪除是物理性刪除,並且邏輯刪除update b_deleted=1 這樣的已經在運行中的設計,咱們的辦法是增長deleted觸發器,生成刪除日誌表,在上報的前置機中,讀取刪除日誌表,並根據業務刪除大數據中心中的數據信息(這時是邏輯刪除,即b_deleted=1)。.net