列的基本操作,约束和集合的ArrayList类

欢迎来到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)

添加检查键

 

    为teacherusers表添加主外关联

    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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值