@@ -57,6 +57,81 @@ func TestAlterTable(t *testing.T) {
5757 },
5858 },
5959 },
60+ {
61+ Name : "Add Unique Constraint" ,
62+ SetUpScript : []string {
63+ "create table t1 (pk int primary key, c1 int);" ,
64+ "insert into t1 values (1,1);" ,
65+ "create table t2 (pk int primary key, c1 int);" ,
66+ "insert into t2 values (1,1);" ,
67+ },
68+ Assertions : []ScriptTestAssertion {
69+ {
70+ // Add a secondary unique index using create index
71+ Query : "CREATE UNIQUE INDEX ON t1(c1);" ,
72+ Expected : []sql.Row {},
73+ },
74+ {
75+ // Test that the unique constraint is working
76+ Query : "INSERT INTO t1 VALUES (2, 1);" ,
77+ ExpectedErr : "unique" ,
78+ },
79+ {
80+ // Add a secondary unique index using alter table
81+ Query : "ALTER TABLE t2 ADD CONSTRAINT uniq1 UNIQUE (c1);" ,
82+ Expected : []sql.Row {},
83+ },
84+ {
85+ // Test that the unique constraint is working
86+ Query : "INSERT INTO t2 VALUES (2, 1);" ,
87+ ExpectedErr : "unique" ,
88+ },
89+ },
90+ },
91+ {
92+ Name : "Add Check Constraint" ,
93+ SetUpScript : []string {
94+ "create table t1 (pk int primary key, c1 int);" ,
95+ "insert into t1 values (1,1);" ,
96+ },
97+ Assertions : []ScriptTestAssertion {
98+ {
99+ // Add a check constraint that is already violated by the existing data
100+ Query : "ALTER TABLE t1 ADD CONSTRAINT constraint1 CHECK (c1 > 100);" ,
101+ ExpectedErr : "violated" ,
102+ },
103+ {
104+ // Add a check constraint
105+ Query : "ALTER TABLE t1 ADD CONSTRAINT constraint1 CHECK (c1 < 100);" ,
106+ Expected : []sql.Row {},
107+ },
108+ {
109+ Query : "INSERT INTO t1 VALUES (2, 2);" ,
110+ Expected : []sql.Row {},
111+ },
112+ {
113+ Query : "INSERT INTO t1 VALUES (3, 101);" ,
114+ ExpectedErr : "violated" ,
115+ },
116+ },
117+ },
118+ {
119+ Name : "Drop Constraint" ,
120+ SetUpScript : []string {
121+ "create table t1 (pk int primary key, c1 int);" ,
122+ "ALTER TABLE t1 ADD CONSTRAINT constraint1 CHECK (c1 > 100);" ,
123+ },
124+ Assertions : []ScriptTestAssertion {
125+ {
126+ Query : "ALTER TABLE t1 DROP CONSTRAINT constraint1;" ,
127+ Expected : []sql.Row {},
128+ },
129+ {
130+ Query : "INSERT INTO t1 VALUES (1, 1);" ,
131+ Expected : []sql.Row {},
132+ },
133+ },
134+ },
60135 {
61136 Name : "Add Primary Key" ,
62137 SetUpScript : []string {
0 commit comments