Define constraint name for primary key : Primary Key « Constraints « SQL Server / T-SQL Tutorial






2> CREATE TABLE customer
3> (
4> cust_id      int          IDENTITY  NOT NULL
5>                           CONSTRAINT cust_pk PRIMARY KEY,
6> cust_name    varchar(30)  NOT NULL
7> )
8> GO
1>
2> EXEC sp_helpconstraint customer
3> GO
Object Name



--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
customer




constraint_type                                                                                                                                    constraint_name
                                                                            delete_action update_action status_enabled status_for_replication constraint_keys











-------------------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------
--------------------------------------------------------------------------- ------------- ------------- -------------- ---------------------- ----------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------
PRIMARY KEY (clustered)                                                                                                                            cust_pk
                                                                            (n/a)         (n/a)         (n/a)          (n/a)                  cust_id












No foreign keys reference table 'customer', or you do not have permissions on referencing tables.
1>
2> drop table customer;
3> GO








7.2.Primary Key
7.2.1.Primary Key Constraint
7.2.2.The PRIMARY KEY Clause
7.2.3.Define constraint name for primary key
7.2.4.PRIMARY KEY (cust_id)
7.2.5.You cannot add another primary key to table
7.2.6.NONCLUSTERED PRIMARY KEY
7.2.7.Using a Multicolumn Primary Key