刚学数据库,请教个问题,谢谢!

syc574937516 2009-11-22 08:59:38
CREATE UNIQUE INDEX 终止,因为发现对象名称 'dbo.销售单' 和索引名称 'xs_inex' 有重复的键


请问这个错误怎么解决?谢谢!
...全文
158 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
syc574937516 2009-11-22
  • 打赏
  • 举报
回复
谢谢啊!找到了
syc574937516 2009-11-22
  • 打赏
  • 举报
回复
谢谢!看不懂啊,有没有例子啊?
ACMAIN_CHM 2009-11-22
  • 打赏
  • 举报
回复
如果不习惯查手册,那么就查GOOGEL

http://msdn.microsoft.com/zh-cn/library/ms189527(SQL.90).aspx
ACMAIN_CHM 2009-11-22
  • 打赏
  • 举报
回复
[Quote]SQL Server 2005 ,帮助里没有。[/Quote]

看来楼主需要学会如何查帮助手册。

SQL Server 2005 Books Online

STR (Transact-SQL)
Returns character data converted from numeric data.

Transact-SQL Syntax Conventions

Syntax

STR ( float_expression [ , length [ , ] ] )


Arguments
float_expression
Is an expression of approximate numeric (float) data type with a decimal point.

length
Is the total length. This includes decimal point, sign, digits, and spaces. The default is 10.

decimal
Is the number of places to the right of the decimal point. decimal must be less than or equal to 16. If decimal is more than 16 then the result is truncated to sixteen places to the right of the decimal point.

Return Types
char

Remarks
If supplied, the values for length and decimal parameters to STR should be positive. The number is rounded to an integer by default or if the decimal parameter is 0. The specified length should be greater than or equal to the part of the number before the decimal point plus the number's sign (if any). A short float_expression is right-justified in the specified length, and a long float_expression is truncated to the specified number of decimal places. For example, STR(12,10) yields the result of 12. This is right-justified in the result set. However, STR(1223,2) truncates the result set to **. String functions can be nested.

Note:
To convert to Unicode data, use STR inside a CONVERT or CAST conversion function.



Examples
The following example converts an expression that is made up of five digits and a decimal point to a six-position character string. The fractional part of the number is rounded to one decimal place.

Copy Code
SELECT STR(123.45, 6, 1)
GO


Here is the result set.



SQL Server 2005 Books Online

ISNULL (Transact-SQL)


Replaces NULL with the specified replacement value.

Transact-SQL Syntax Conventions

Syntax

ISNULL ( check_expression , replacement_value )


Arguments
check_expression
Is the expression to be checked for NULL. check_expression can be of any type.

replacement_value
Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expresssion.

Return Types
Returns the same type as check_expression.

Remarks
The value of check_expression is returned if it is not NULL; otherwise, replacement_value is returned after it is implicitly converted to the type of check_expression, if the types are different.

Examples
A. Using ISNULL with AVG
The following example finds the average of the weight of all products. It substitutes the value 50 for all NULL entries in the Weight column of the Product table.

Copy Code
USE AdventureWorks;
GO
SELECT AVG(ISNULL(Weight, 50))
FROM Production.Product;
GO


Here is the result set.

Copy Code
--------------------------
59.79

(1 row(s) affected)


B. Using ISNULL
The following example selects the description, discount percentage, minimum quantity, and maximum quantity for all special offers in AdventureWorks. If the maximum quantity for a particular special offer is NULL, the MaxQty shown in the result set is 0.00.

Copy Code
USE AdventureWorks;
GO
SELECT Description, DiscountPct, MinQty, ISNULL(MaxQty, 0.00) AS 'Max Quantity'
FROM Sales.SpecialOffer;
GO


Here is the result set.

Copy Code
Description DiscountPct MinQty Max Quantity
--------------- ------------- -------- ---------------
No Discount 0.00 0 0
Volume Discount 0.02 11 14
Volume Discount 0.05 15 4
Volume Discount 0.10 25 0
Volume Discount 0.15 41 0
Volume Discount 0.20 61 0
Mountain-100 Cl 0.35 0 0
Sport Helmet Di 0.10 0 0
Road-650 Overst 0.30 0 0
Mountain Tire S 0.50 0 0
Sport Helmet Di 0.15 0 0
LL Road Frame S 0.35 0 0
Touring-3000 Pr 0.15 0 0
Touring-1000 Pr 0.20 0 0
Half-Price Peda 0.50 0 0
Mountain-500 Si 0.40 0 0

(16 row(s) affected)


SQL Server 2005 Books Online

LTRIM (Transact-SQL)

Returns a character expression after it removes leading blanks.

Transact-SQL Syntax Conventions

Syntax

LTRIM ( character_expression )


Arguments
character_expression
Is an expression of character or binary data. character_expression can be a constant, variable, or column. character_expression must be of a data type, except text, ntext, and image, that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert character_expression.

Return Type
varchar or nvarchar

Remarks
Compatibility levels can affect return values. For more information about compatibility levels, see sp_dbcmptlevel (Transact-SQL).

Examples
The following example uses LTRIM to remove leading spaces from a character variable.

Copy Code
DECLARE @string_to_trim varchar(60)
SET @string_to_trim = ' Five spaces are at the beginning of this
string.'
SELECT 'Here is the string without the leading spaces: ' +
LTRIM(@string_to_trim)
GO


Here is the result set.

Copy Code
------------------------------------------------------------------------
Here is the string without the leading spaces: Five spaces are at the beginning of this string.

(1 row(s) affected)

syc574937516 2009-11-22
  • 打赏
  • 举报
回复
SQL Server 2005 ,帮助里没有。
ACMAIN_CHM 2009-11-22
  • 打赏
  • 举报
回复
你用的什么数据库?

先在数据库的相关帮助文件中搜索一下这三个函数的说明和例子。
syc574937516 2009-11-22
  • 打赏
  • 举报
回复
谢谢,再请问函数str(),isnull()和Ltrim()怎么用?
ACMAIN_CHM 2009-11-22
  • 打赏
  • 举报
回复
在你的表中找到这个重复值的记录,然后删除后再重 CREATE UNIQUE INDEX

2,209

社区成员

发帖
与我相关
我的任务
社区描述
其他数据库开发 其他数据库
社区管理员
  • 其他数据库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧