哈喽,欢迎来到我们的
狗刨网,今天我们讲了很多有趣的东西,有数据库的约束,还有arrylist的应用,首先我们每天都会有新的更新,欢迎来到我们
的网站上看哦。
一、列的基本操作
增加一列
Alter table 表名 add 列名 类型(长度) null
例如:Alter table student add age int null
更改列类型
alter table 表名 alter column 列名数据类型(长度)
Alter table teacher alter column age varchar(3)
删除列
alter table 表名 drop column 列名
Alter table teacher drop column age
主键约束
alter table 表名add constraint 主键别名primary key (主键列)
Alter table teacher add constraint t_pk primary key(id)
唯一约束
Alter table 表名 add constraint 唯一键别名unique (唯一键列)
Alter table teacher add constraint t_un unique(name)
默认约束
Alter table 表名 add constraint 默认键别名 default (‘默认值’) for 默认键
Alter table teacher add constraint t_de default('男') for sex
检查约束
Alter table 表名 add constraint 检查键别名check(stuAge>=15 andstuAge<=40)
Alter table teacher add constraint t_ch check(age>=15 and age<=40)
删除约束
Alter table 表名 drop constrant 约束别名
二、arrylist类
特点:1、有序的对象列表。
2、没有固定的大小,可以根据需要不断增长。
3、默认大小为16个元素,当添加第17个元素时会自动扩展到32个。
4、可以显示的指定其容量。
5、可以存储不同类型的元素,因为所有arrylist中的元素都是对象。
List:泛型集合可以约束集合内的元素类型,编译时检查类型约束,无需装箱拆箱操作
加上using System.Collections.Generic;
List<string> list=new List<string>();
List<Person> list = new List<Person>();
三、泛型集合
List<对象>
List<string> list=new List<string>();
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
foreach (string i in list) {
Console.WriteLine(i);
}
2、ArrayList 的方法:
--Add(object):把一个对象添加到 ArrayList 的末尾
--Insert(index,object):在指定位置插入一个对象
--Remove(object):移除一个对象
--RemoveAt(index):移除一个对象
--Clear():移除所有元素
--Sort:对ArrayList 中的元素进行排序
这就是我们今天讲的主要内容,我们每天都会更新新的内容哟,欢迎来到我们的狗刨网,俗话说每天的进步就在于一点一滴的积累,每天自己进步多
一点,收获就非常大,欢迎来我们的
狗刨网看哟。