欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多U3D资源、U3D培训视频、U3D教程、我们致力于打造业内unity3d培训、学习第一品牌。
今天学习了列的基本操作,约束和集合的ArrayList类
列的基本操作
添加一列
alter table 表名 add 列名 类型(长度) null
例:
alter table student add age int null
--为student 表添加一个age列
更改一个列的类型
例:
alter table 表名 alter column 列名 数据类型(长度)
alter table student alter column age int
--把age列的数据类型改为int型
删除一列
alter table 表名 drop column 列名
alter table student drop column age
删除student表中的age列
约束
主键约束
alter table 表名 add constraint 主键别名 primary key (主键列)
alter table teacher add constraint t_pk primary key(id)
--将teacher表中的id设为主键。
唯一键约束
alter table 表名 add constraint 唯一键别名 unique (唯一键列)
alter table teacher add constraint t_un unique(name)
把name列设为唯一键列
默认键约束
alter table 表名 add constraint 默认键别名 default (‘默认值’) for 默认键
alter table teacher add constraint t_de default('男') for sex
把sex 设置为默认键,默认属性为“男”
检查键约束
alter table 表名 add constraint 检查键别名check(stuAge>=15 and stuAge<=40)
alter table teacher add constraint t_ch check(age>=15 and age<=40)
添加检查键
为teacher和users表添加主外关联
alter table score add constraint t_fk foreign key(uid) references users(id)
删除约束
alter table 表名 drop constraint 约束别名
集合
ArrayList类
使用大小可按需动态增加的数组
ArrayList al = new ArrayList();
int a=new int[6] { 9, 3, 7, 2, 4, 8 };
al.Add(100);//单个添加
foreach (int number in a)
{
al.Add(number);//集体添加方法一
}
al.Remove(3);//移除值为3的 数据
al.RemoveAt(3);//移除集合中的三个数据,(集合从0开始)
泛型集合
List<对象>
List<string> list=new List<string>();
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
foreach (string i in list) {
Console.WriteLine(i);
}
public class Person {
private string name;
//public void SetName(string name) {
// this.name = name;
//}
//public string GetName() {
// return name;
//}
public string Name
{
set
{
name = value;
}
get
{
return name;
}
}
}
List<Person> list = new List<Person>();
Person p = new Person();
p.Name = "zhangsan";
//p.SetName("zhangsan");
list.Add(p);
foreach (Person pp in list)
{
//Console.WriteLine(pp.GetName());
Console.WriteLine(pp.Name);
}
更多精彩内容请关注:http://www.gopedu.com/