?? 員工表和退休員工表.txt
字號(hào):
----建立公司數(shù)據(jù)庫(kù)
use master
go
if exists(select * from sysdatabases where name='公司數(shù)據(jù)庫(kù)')
drop database 公司數(shù)據(jù)庫(kù)
CREATE DATABASE 公司數(shù)據(jù)庫(kù)
ON PRIMARY
( NAME = 公司數(shù)據(jù)庫(kù),
FILENAME = 'D:\公司數(shù)據(jù)庫(kù)\公司數(shù)據(jù)庫(kù).mdf',
SIZE = 5MB,
MAXSIZE = 50MB,
FILEGROWTH = 1MB)
LOG ON
( name=公司數(shù)據(jù)庫(kù)_log,
FILENAME = 'D:\公司數(shù)據(jù)庫(kù)\公司數(shù)據(jù)庫(kù)_log.ldf',
SIZE = 2MB,
MAXSIZE = 50MB,
FILEGROWTH = 10%)
go
----建立員工表
use 公司數(shù)據(jù)庫(kù)
go
if exists(select * from sysobjects where name='員工表')
drop table 員工表
use 公司數(shù)據(jù)庫(kù)
create table 員工表(
員工編號(hào) int primary key not null,
員工姓名 varchar (50) not null,
)
----往員工表中插入以下數(shù)據(jù)
insert into 員工表(員工編號(hào),員工姓名) values ('001','阿呆')
insert into 員工表(員工編號(hào),員工姓名) values ('002','阿坡')
insert into 員工表(員工編號(hào),員工姓名) values ('003','阿燦')
insert into 員工表(員工編號(hào),員工姓名) values ('004','阿清')
insert into 員工表(員工編號(hào),員工姓名) values ('005','阿猴')
----建立退休員工表
use 公司數(shù)據(jù)庫(kù)
go
if exists(select * from sysobjects where name='退休員工表')
drop table 退休員工表
use 公司數(shù)據(jù)庫(kù)
create table 退休員工表(
退休員工編號(hào) int primary key not null,
退休員工姓名 varchar (50) not null,
)
----往退休員工表中插入以下數(shù)據(jù)
insert into 退休員工表(退休員工編號(hào),退休員工姓名) values ('401','阿珍')
insert into 退休員工表(退休員工編號(hào),退休員工姓名) values ('402','阿華')
insert into 退休員工表(退休員工編號(hào),退休員工姓名) values ('403','阿傳')
insert into 退休員工表(退休員工編號(hào),退休員工姓名) values ('404','阿鐠')
----創(chuàng)建員工表和退休員工表兩個(gè)表之間的觸發(fā)器,使刪除員工表的數(shù)據(jù)的同時(shí)退休員工表增加相應(yīng)的數(shù)據(jù)
use 公司數(shù)據(jù)庫(kù)
go
create trigger trig_tx
on 員工表
for delete
as
if not exists(select * from sysobjects where name='退休員工表')
select * into 員工表 from deleted
else
insert into 退休員工表 select * from deleted
go
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -