Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting unique constraint for a table field in SAP [closed]

Tags:

sap

How to add constraint for a field in a table that should only contain unique values in SAP?

like image 903
Sathya Avatar asked May 17 '11 09:05

Sathya


People also ask

How do I add a unique constraint to an existing table?

The syntax for creating a unique constraint using an ALTER TABLE statement in SQL Server is: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n); table_name.

How do you give a unique constraint?

The syntax for creating a unique constraint using an ALTER TABLE statement in MySQL is: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n); table_name.

How do you modify unique constraints?

To modify a unique constraintIn the Object Explorer, right-click the table containing the unique constraint and select Design. On the Table Designer menu, click Indexes/Keys.... In the Indexes/Keys dialog box, under Selected Primary/Unique Key or Index, select the constraint you wish to edit.

Can a table have two unique constraints?

Both the UNIQUE and PRIMARY KEY constraints provide a guarantee for uniqueness for a column or set of columns. A PRIMARY KEY constraint automatically has a UNIQUE constraint. However, you can have many UNIQUE constraints per table, but only one PRIMARY KEY constraint per table.


2 Answers

So, in your table; you wish there weren't any NON-KEY attributes, right?

  • SE11 > Goto > Indexes
  • Create an INDEX on this field & make it unique
  • SY-SUBRC to be made non-zero + Use MANDT
like image 93
closebrace Avatar answered Sep 29 '22 11:09

closebrace


If you want to do it using code...

ALTER TABLE dbo.MyTable ADD CONSTRAINT MyTable_Code_Name_UniqueKey UNIQUE (Code, Name)
like image 33
AndrewD Avatar answered Sep 29 '22 09:09

AndrewD