faqts : Computers : Databases : Microsoft SQL Server

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 9 people (67%) answered Yes
Recently 6 of 9 people (67%) answered Yes

Entry

Database: Microsoft SQL server: SQL: Table: Create: How create table with a primary key, using SQL?

Dec 22nd, 2003 13:05
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 22 December 2003 - 09:57 pm -------------------

Database: Microsoft SQL server: SQL: Table: Create: How create table 
with a primary key, using SQL?

---

For example, you want to create
one table with person information
and a primary key

---

Steps: Overview:

 1. -Possibly design your tables

      Table 1:

      ---

      Table 'Person'
      ----------------------------------------------------
      NAME                     PERSONKEY (=PRIMARY KEY)
      ----------------------------------------------------
      john doe                 1
      vanessa beau             2
      ----------------------------------------------------

 2. -Create your tables

     1. Creating this table 1 in SQL

        ---

      CREATE TABLE Person (
       Name VARCHAR( 50 ) NOT NULL,
       PersonKey INT NOT NULL,
       PRIMARY KEY ( PersonKey )
      );

---
---

More in general:

---

 CREATE TABLE <your tablename> (
  <your columnname1> <Datatype1> [NOT NULL],
  <your columnname2> <Datatype2> [NOT NULL],
  ...
  <Columnnamelast> <Datatypelast> [NOT NULL],
  [PRIMARY KEY ( <your columnnameI> ) ]
 );

---
---

Internet: see also:

---

Database: Microsoft SQL server: SQL: Operation: Overview:Can you give 
an overview of SQL operations?
http://www.faqts.com/knowledge_base/view.phtml/aid/27560/fid/147


----------------------------------------------------------------------