续:
——删除数据
Truncate table stu <删除内容,释放空间,但不删除定义>
每条语句都是一道例题,大家可以参考,格式我会给标红,比较容易学习和记忆~
列的基本操作
——增加一列
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
Default ()是默认值
——检查约束
Alter table 表名 add constraint 检查键别名check(stuAge>=15 andstuAge<=40)
Alter table teacher add constraint t_ch check(age>=15 and age<=40)
——主外关联
alter table 表名1 add constraint 外键别名 foreign key(外键) references表名2(主键)
Alter table score add constraint t_fk foreign key(uid) references users(id)
——删除约束
alter table 表名 drop constraint 约束别名
alter table score drop constraint t_fk
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ArrayList:
数组:固定长度的一段内存。
ArrayList:可以理解为可以动态增加内存的数组,是一种链表。
list是一种范型链表,解决了ArrayList对于值类型需要装箱拆箱的缺点。
//ArrayList类对象被设计成为一个动态数组类型,其容量会随着需要而适当的扩充
方法
1:Add()向数组中添加一个元素,
2:Remove()删除数组中的一个元素
3:RemoveAt(inti)删除数组中索引值为i的元素
4:Reverse()反转数组的元素
5:Sort()以从小到大的顺序排列数组的元素
6:Clone()复制一个数组
Add()向数组中添加一个元素
举例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;//在C#中使用ArrayList必须引用Collections类
namespace arrayD
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 1,2,3,4,5};
ArrayList list = new ArrayList(arr);
Console.WriteLine("原始ArrayList类中的数据");
foreach (int i in list)
{
Console.Write(i+" ");
}
Console.WriteLine();
Console.WriteLine("使用add方法添加");
for (int i = 1; i < 5; i++)
{
list.Add(i+arr.Length);
}
foreach (int i in list)
{
Console.Write(i + "");
}
Console.WriteLine();
Console.WriteLine("使用Insert方法添加");
list.Insert(5,6);
foreach (int i in list)
{
Console.Write(i + "");
}
Console.WriteLine();
Console.ReadLine();
}
}
}
ArrayList元素的删除
举例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace arrayDel
{
class Program
{
static void Main(string[] args)
{
int[] arr = new int[] { 1, 2, 3, 4, 5, 6 };
ArrayList list = new ArrayList(arr);
Console.WriteLine("删除前ArrayList元素");
foreach (int i in list)
{
Console.Write(i+" ");
}
Console.WriteLine();
list.RemoveRange(0, 3);//使用RemoveRange方法删除指定的元素
Console.WriteLine("删除后ArrayList元素");
foreach (int i in list)
{
Console.Write(i + " ");
}
Console.ReadLine();
}
}
}
ArrayList元素的遍历
举例:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace arrayBl
{
class Program
{
static void Main(string[] args)
{
ArrayList arr = new ArrayList();
arr.Add("unity学习");
arr.Add("努力在狗刨学习网学习unity");
foreach (string i in arr)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
List泛型集合
泛型是C# 2.0中的新增元素(C++中称为模板),主要用于解决一系列类似的问题。这种机制允许将类名作为参数传递给泛型类型,并生成相应的对象。将泛型(包括类、接口、方法、委托等)看作模板可能更好理解,模板中的变体部分将被作为参数传进来的类名称所代替,从而得到一个新的类型定义。
主要利用System.Collections.Generic命名空间下面的List泛型类创建集合。
List<T>
a.T为列表中元素类型,现在以string类型作为例子
如: List<string> mList = newList<string>();
b.增加元素:List. Add(T item) 添加一个元素
如:mList.Add("狗刨网");
c.插入元素:Insert(int index, T item); 在index位置添加一个元素
如:mList.Insert(1,"狗刨网");
d.删除元素: List. Remove(T item) 删除一个值
如:mList.Remove("狗刨网");
List. RemoveAt(int index); 删除下标为index的元素
如.:mList.RemoveAt(0);
List. RemoveRange(int index,int count); 从下标index开始,删除count个元素
如.:mList.RemoveRange(3, 2); //超出删除的范围会出错
注:删除某元素后,其后面的元素下标自动跟进
e.判断是否存在List:List. Contains(T item) 得到的结果是返回true或false
f.排序:List. Sort () //默认是元素第一个字母按升序
给List里面元素顺序反转:
List. Reverse () //可以与List. Sort ()配合使用,达到想要的效果
遍历List中元素:
foreach (T element in mList) T的类型与mList声明时一样
{
Console.WriteLine(element);
}
g.List清空:List. Clear ()
如:mList.Clear();
欢迎来到unity学习、unity培训、unity企业培训教育专区,这里有很多U3D资源、U3D培训视频U3D教程、U3D常见问题、U3D项目源码,我们致力于打造业内unity3d培训、学习第一品牌。