-
Notifications
You must be signed in to change notification settings - Fork 0
/
View, Rule, Default, Variables, Userdefiend.sql
100 lines (74 loc) · 1.95 KB
/
View, Rule, Default, Variables, Userdefiend.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
-- On Testing Database
-- Create Default
create table Student
(
ID int,
[Name] nvarchar(20),
City nvarchar(20),
Bouns int,
constraint Chk1 check (Bouns>5000)
)
create table Instructor
(
ID int,
[Name] nvarchar(20),
City nvarchar(20),
Salary int,
constraint Chk2 check (Salary>5000)
)
create table Center
(
ID int,
[Name] nvarchar(20),
City nvarchar(20),
Rent int,
)
CREATE DEFAULT dcity as 'Minia';
sp_bindefault dcity, '[Student].[City]'
sp_bindefault dcity, '[Instructor].[City]'
sp_bindefault dcity, '[Center].[City]'
INSERT INTO Student(Name) values('TestDefault')
SELECT * FROM Student
sp_unbindefault '[Student].[City]'
sp_unbindefault '[Instructor].[City]'
sp_unbindefault '[Center].[City]'
drop default dCity
--==============================================
--==============================================
--==============================================
create rule R1 as @col >5000
sp_bindrule R1, 'Student.Salary'
--==============================================
--==============================================
--==============================================
CREATE VIEW Student_Info
AS(
SELECT ID ,[Name], City, Bouns FROM Student
)
SELECT * FROM Student_Info
select Name from Student_Info
select Name from Student_Info
where ID= NULL
--===================================================
--===================================================
declare @MyVar nvarchar(11)
--assign value using set
set @MyVar ='test'
select @MyVar
--assign value using select
select @MyVar ='t'
print @MyVar
--==============================================
--=============================================
--==============================================
create type Tel from nvarchar(11) not null
--or--
sp_addtype SSN from 'nvarchar(50)','not null'
create table Dept
(
ID int ,
Phone Tel
)
alter table Dept
alter column Phone nvarchar(11) not null
drop type Tel