Thursday, March 29, 2012

CREATE TABLE Template

I accidentally altered the CREATE TABLE template from SQL Server Management Studio Express. Now I don't have the original. Could somebody please post CREATE TABLE template.

-- =========================================

-- 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

|||

Or the simplified version:

Create Table MyTable(FirstField varchar(50), SecondField int)

or...

when in doubt >> Right Click in Management Studio to create a new table manually

Adamus

|||

Thanks, joeydj,

johncelmer

sql

No comments:

Post a Comment