View Full Version : جلوگیری از تکرار و افزایش کارایی
mamizadeh
پنج شنبه 23 اسفند 1386, 21:00 عصر
با سلام
اگر در یک جدول فبلدی داشته باشیم که کلید اصلی باشد خوب طبیعی است که عمرا اجازه تکراری درج کردن رو به کاربر داده بشه
ولی من یه سوال دارم فیلدی داریم که کلید اصلی نیست ولی از طرفی هم نمی خواهیم تکراری در میان باشه مثلا فرض کنید در جدولی که آی دی داریم که اون فیلد کلید اصلی هستش و نام هم داریم و همچنین فیلد های دیگه می خواهیم کاربر وقتی نام تکراری وارد کرد اجازه نده البته نه با کد نویسی بلکه با امکانات خود sql چطور در اکسس قابلیتی برای فیلد ها وجود داره که وقتی Doubleable اون رو no کنیم اجازه تکراری درج شدن را نمی ده ولی کلید اصلی هم نیست این عمل در sql چطوری هستش
با تشکر
Elham_gh
شنبه 25 اسفند 1386, 11:09 صبح
روی اون فیلدها ایندکسUnique بزنید
mamizadeh
یک شنبه 26 اسفند 1386, 17:59 عصر
روی اون فیلدها ایندکسUnique بزنید
دوست گرامی چطور این کارو انجام بدم :گریه:
می تونید کامل توضیح بدهید که چطوری این کارو انجام بدم
با تشکر
Elham_gh
دوشنبه 27 اسفند 1386, 12:01 عصر
عینا کپی از Book OnLine:
To create a unique index
1.In Object Explorer, right-click the table and click Modify
The table opens in Table Designer.
2.From the Table Designer menu, click Indexes/Keys
3.Click Add. The Selected Primary/Unique Key or Index list displays the system-assigned name of the new index
4.In the grid, click Type
5.Choose Index from the drop-down list to the right of the property
6.Under Column name, select the columns you want to index. You can select up to 16 columns. For optimal performance, select only one or two columns per index. For each column you select, indicate whether the index arranges values of this column in ascending or descending order.
7.In the grid, click Is Unique
8.Choose Yes from the drop-down list to the right of the property
9.Select the Ignore duplicate keys option if you want to ignore data that would create a duplicate key in the unique index (with the INSERT statement).
The index is created in the database when you save the table or diagram.
Note:
You cannot create a unique index on a single column if that column contains NULL in more than one row. Similarly, you cannot create a unique index on multiple columns if the combination of columns contains NULL in more than one row. These are treated as duplicate values for indexing purposes.
و مثال با استفاده از T_SQL:
CREATE UNIQUE INDEX AK_UnitMeasure_Name
ON Production.UnitMeasure(Name);
GO
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.