-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlter.sql
More file actions
61 lines (40 loc) · 1023 Bytes
/
Alter.sql
File metadata and controls
61 lines (40 loc) · 1023 Bytes
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
-- Create Table
-- Rename Table
alter table book
rename to books
-- Add Column
alter table books
add column publishedDate date;
-- Drop Column
alter table books
drop column rating
-- Rename Column
alter table books
rename column category to categories
-- Change Data Type
alter table books
alter column price type int using price::int
-- Set Default Value
alter table books
alter column publishedDate set default current_date
-- Drop Default Value
alter table books
alter column publishedDate drop default
-- Set NOT NULL Constraint
alter table books
alter column categories set not null
-- Drop NOT NULL Constraint
alter table books
alter column categories drop not null
-- Add UNIQUE Constraint
alter table books
add constraint title_unique unique (title)
-- Drop UNIQUE Constraint
alter table books
drop constraint title_unique
-- Add PRIMARY KEY Constraint
alter table books
add constraint id_primary primary key (id)
-- Drop PRIMARY KEY Constraint
alter table books
drop constraint id_primary