列的基本操作,約束和集合的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/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章