Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

My first SQL program.

Posted on 2008-10-01
4
Medium Priority
?
569 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 1500 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

670 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