locked
Making Tables RRS feed

  • Question

  • Can any one tell me hoe to create tables in sql i am new user. plz
    Friday, February 15, 2013 7:57 PM

Answers

  • The following blog has examples for CREATE TABLE-s:

    http://www.sqlusa.com/bestpractices2005/bankdatabase/

    Example for the Product (copy of Products) table CREATE in Northwind database:

    USE Northwind;
    
    CREATE TABLE dbo.Product(
    	ProductID int IDENTITY(1,1) PRIMARY KEY,
    	ProductName nvarchar(40) NOT NULL UNIQUE,
    	SupplierID int NULL REFERENCES dbo.Suppliers,
    	CategoryID int NULL REFERENCES dbo.Categories ,
    	QuantityPerUnit nvarchar(20) NULL,
    	UnitPrice money NULL DEFAULT ((0)) CHECK  ((UnitPrice>=(0))),
    	UnitsInStock smallint NULL DEFAULT ((0)) CHECK  ((UnitsInStock>=(0))),
    	UnitsOnOrder smallint NULL DEFAULT ((0)) CHECK  ((UnitsOnOrder>=(0))),
    	ReorderLevel smallint NULL DEFAULT ((0)) CHECK  ((ReorderLevel>=(0))),
    	Discontinued bit NOT NULL DEFAULT ((0))
    );
    
    


    Kalman Toth Database & OLAP Architect
    Paperback / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

    Saturday, February 16, 2013 3:54 AM

All replies

  • http://www.bing.com/search?q=how+to+create+tables+in+sql+server

    David


    David http://blogs.msdn.com/b/dbrowne/

    Friday, February 15, 2013 8:05 PM
  • Try -

    http://www.w3schools.com/sql/sql_create_table.asp

    Basic syntax -

    CREATE TABLE table_name
     (
     column_name1 data_type,
     column_name2 data_type,
     column_name3 data_type,
     ....
     )


    Narsimha

    Friday, February 15, 2013 10:48 PM
  • The following blog has examples for CREATE TABLE-s:

    http://www.sqlusa.com/bestpractices2005/bankdatabase/

    Example for the Product (copy of Products) table CREATE in Northwind database:

    USE Northwind;
    
    CREATE TABLE dbo.Product(
    	ProductID int IDENTITY(1,1) PRIMARY KEY,
    	ProductName nvarchar(40) NOT NULL UNIQUE,
    	SupplierID int NULL REFERENCES dbo.Suppliers,
    	CategoryID int NULL REFERENCES dbo.Categories ,
    	QuantityPerUnit nvarchar(20) NULL,
    	UnitPrice money NULL DEFAULT ((0)) CHECK  ((UnitPrice>=(0))),
    	UnitsInStock smallint NULL DEFAULT ((0)) CHECK  ((UnitsInStock>=(0))),
    	UnitsOnOrder smallint NULL DEFAULT ((0)) CHECK  ((UnitsOnOrder>=(0))),
    	ReorderLevel smallint NULL DEFAULT ((0)) CHECK  ((ReorderLevel>=(0))),
    	Discontinued bit NOT NULL DEFAULT ((0))
    );
    
    


    Kalman Toth Database & OLAP Architect
    Paperback / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

    Saturday, February 16, 2013 3:54 AM