Tutorials Forums
     Tutorials Videos
        Sign Up Now For FREE
Welcome, Guest
Username Password: Remember me
SQL SERVER HELP, SQL SERVER TUTORIALS, SQL SERVER PROGRAMMING, SQL SERVER CODE


SQL Server is a relational DMBS written for the Windows platform by Microsoft. SQL Server is a high-end and high-performance solution, for applications that interact with a database. Its use has been increasing because of the number of web applications that feature a data base back end.
  • Page:
  • 1

TOPIC: Creating a Table

Creating a Table 04 Feb 2010 14:14 #255

Introduction
To create a table, you can follow this formula:
CREATE TABLE Country(Column1, Column2, Column3)
or:
 
CREATE TABLE Country(
Column1,
Column2,
Column3);

Each column is created as:
ColumnName DataType Options
Here is an example:
CREATE TABLE Customers (
DrvLicNbr nvarchar(32),
DateIssued DATE,
DateExpired date,
FullName nvarchar(50),
Address NVARCHAR(120),
City NvarChar(40),
State NVarChar(50),
PostalCode nvarchar(20),
HomePhone nvarchar(20),
OrganDonor BIT);
GO

To start from a sample code, open an empty Query window and display the Template Explorer. From the Template Explorer, expand Table. Drag Create Table and drop it in the Query window:
-- =========================================
-- Create table template
-- =========================================
USE <database, sysname, AdventureWorks>
GO
 
IF OBJECT_ID('<schema_name, sysname, dbo>.<table_name,
sysname, sample_table>'
, 'U')
IS NOT NULL
DROP TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table>
GO
 
CREATE TABLE <schema_name, sysname, dbo>.<table_name, sysname, sample_table>
(
<columns_in_primary_key, , c1> <column1_datatype, , int>
<column1_nullability,, NOT NULL>,
<column2_name, sysname, c2> <column2_datatype, , char(10)>
<column2_nullability,, NULL>,
<column3_name, sysname, c3> <column3_datatype, , datetime>
<column3_nullability,, NULL>,
CONSTRAINT <contraint_name, sysname, PK_sample_table>
PRIMARY KEY (<columns_in_primary_key, , c1>)
)
GO

You can then modify/customize this code.

To visually create a table, in the Object Explorer, expand the the database and expand its Tables node. Right-click the Tables node and click New Table... Enter a name for each column and select its data type:
  • CE
  • OFFLINE
  • Administrator
  • Posts: 197
  • Karma: 78
CodersEngine
  • Page:
  • 1
Time to create page: 0.54 seconds