Solved

My first SQL program.

Posted on 2008-10-01
4
558 Views
Last Modified: 2010-04-21
I am just learning how to use SQL 2005 and my first program is not working.  My operating system is windows XP and I downloaded SQL 2005 free trail from the web site.  When I executed my program I received a list of errors:
Msg 170, Level 15, State 1, Line 8
Line 8: Incorrect syntax near 'NAME'.
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'Table'.
Msg 156, Level 15, State 1, Line 24
Incorrect syntax near the keyword 'Table'.
Msg 156, Level 15, State 1, Line 28
Incorrect syntax near the keyword 'TABLE'.

I am unable to figure out what is wrong.
My code is below.  Any help will be most appreciated.

CREATE DATABASE Kudler_Fine_Foods
      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods.mdf',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
LOG ON
      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods_LOG.LDF',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
GO
-- =========================================
-- Create table template
-- =========================================

CREATE TABLE Employee Table
 (
       Employee_ID varchar (3) NOT NULL,
       Last_Name VARCHAR (30),
       First_Name VARCHAR (30),
       Address VARCHAR (45),
       City VARCHAR (15),
       State VARCHAR (3),
       Telephone_area_code VARCHAR (3) NULL,
       ,...n
       Telephone_number VARCHAR (8) NULL,
       EEO-1 Classification VARCHAR (30),
       ,...n
       Hire_date VARCHAR (10) NULL,
       Salary VARCHAR (10)
       Gender VARCHAR (2),
       Age INT (2)
       Foreign  Key From Job Title table VARCHAR (50),
       CREATE UNIQUE INDEX Employee_ID
       ON Employee Table (Employee_ID
       PRIMARY KEY (Employee_ID)
 );

 CREATE TABLE Job_Title TABLE
 (
       EEO-1 Classification VARCHAR (30),
       ,...n
       Job_Title VARCHAR (50),
       Job Description VARCHAR (170),
       Exempt/Non-Exempt Status VARCHAR (3),
       PRIMARY KEY (EEO-1 Classification)
 );
 --=========================================--
 -- Insert Data into Employee Table
 --=========================================--

 INSERT INTO [Kudler_Fine_Foods].[dbo].[Employee]
 (
       [Employee_ID], [Last_Name], [First_Name], [Address], [City], [State],
 [Telephone_area_code], [.....n], [Telephone_number], [EEO-1
 Classification], [....n], [Hire_date], [Salary], [Gender], [Age], [Job
 Title]
 )
 VALUES
 (
       '1', 'Edelman', 'Glenn', '175 Bishops Lane', 'La Jolla', 'Ca', '619', '', '555-0199', 'Sales Workers', '', '10-07-2003', '$21,500', 'M', '64', 'Cashier'
 )
0
Comment
Question by:Mystified-One
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 500 total points
ID: 22619514
You can view the syntax for creating databases here:
http://msdn.microsoft.com/en-us/library/ms176061.aspx


CREATE DATABASE Kudler_Fine_Foods
on      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods.mdf',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
LOG ON
      (
      NAME='Kudler_Fine_Foods',
      FILENAME='H:\SQLData\KudlerFineFoods_LOG.LDF',
      SIZE=1000KB,
      MAXSIZE=1GB,
      FILEGROWTH=1000KB
      )
GO

 CREATE TABLE Job_Title TABLE
should be  
CREATE TABLE Job_Title

TABLE goes before, not after

don't put numeric values

 INSERT INTO [Kudler_Fine_Foods].[dbo].[Employee]
 (
       [Employee_ID], [Last_Name], [First_Name], [Address], [City], [State],
 [Telephone_area_code], [.....n], [Telephone_number], [EEO-1
 Classification], [....n], [Hire_date], [Salary], [Gender], [Age], [Job
 Title]
 )
 VALUES
 (
       '1', ....

in quotes

 INSERT INTO [Kudler_Fine_Foods].[dbo].[Employee]
 (
       [Employee_ID], [Last_Name], [First_Name], [Address], [City], [State],
 [Telephone_area_code], [.....n], [Telephone_number], [EEO-1
 Classification], [....n], [Hire_date], [Salary], [Gender], [Age], [Job
 Title]
 )
 VALUES
 (
       1,
0
 

Author Comment

by:Mystified-One
ID: 22619624
So if I am reading correctly I need a add

CREATE DATABASE database_name
    [ ON
        [ PRIMARY ] [ <filespec> [ ,...n ]
        [ , <filegroup> [ ,...n ] ]
    [ LOG ON { <filespec> [ ,...n ] } ]
    ]
    [ COLLATE collation_name ]
    [ WITH <external_access_option> ]
]
[;]

To attach a database
CREATE DATABASE database_name
    ON <filespec> [ ,...n ]
    FOR { ATTACH [ WITH <service_broker_option> ]
        | ATTACH_REBUILD_LOG }
[;]

in front of my program?
0
 

Author Closing Comment

by:Mystified-One
ID: 31502191
I need to fully read the information from the link and work with it before knowing if it fully answers my question.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 22620121
I'm not sure your use of the word "program" is correct.  What you are writing is a SQL script.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now