To create a primary key
- Using SQL Server Management Studio
2. In Table Designer, click the row selector for the database column you want to define as the primary key. If you want to select multiple columns, hold down the CTRL key while you click the row selectors for the other columns.
3. Right-click the row selector for the column and select Set Primary Key.
- Using Transact-SQL
2. On the Standard bar, click New Query.
3. Copy and paste the following example into the query window and click Execute. The example creates a primary key on the column .
ALTER TABLE tablename ADD CONSTRAINT PK_ConName PRIMARY KEY CLUSTERED (column);
To create a primary key in a new table
1. In Object Explorer, connect to an instance of Database Engine.
2. On the Standard bar, click New Query.
2. On the Standard bar, click New Query.
3. Copy and paste the following example into the query window and click Execute. The example creates a table and defines a primary key on the column .
CREATE TABLE tablename ( columnName datatype NOT NULL, CONSTRAINT PK_ConName PRIMARY KEY CLUSTERED (column) );
Friends, If you like this post, please share with your friends on Facebook and Google+ and recommend us on Google using the g+1 button on the top right hand corner.
No comments:
Post a Comment