SQL Begining!

Posted on 1999-07-18
Medium Priority
Last Modified: 2010-04-06
I'm new in sql and DB and I need to know how to connect mssql server how to create - update tables,  send a query?
With code please.
Question by:ahmosa
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

Expert Comment

ID: 1389366
First, you need provide an alias.
You can create ODBC alias, or BDE alias to the server.
To create BDE alias, just enter to Database Explorer, create new "MSSQL" database and fill "SERVER NAME" and "DATABASE NAME" parameters.
Now you can work with that database from Delphi.

To create tables, install SQL Server client applications.

LVL 27

Expert Comment

ID: 1389367
hi ahmosa,

take a look to this sql-tutorial

its good for the basic understanding of the sql-language

LVL 15

Accepted Solution

simonet earned 800 total points
ID: 1389368
Hello, ahmosa

Connecting to MS-SQL from Delphi is as simple as dropping a TDatabase component on a form to data-module and set a few properties on it, like Slavak pointed out:

Add these parameters to the PARAMS property of the TDatabase component

USER NAME=name of user

Additionally there may have other properties that are MS-SQL specific and will depend on what sort of connection you're trying to make to the server.

Now, on the TDatabase component itself, set other properties, like AliasName and DatabaseName. Alias name will be the name of the connection as the other Delphi components will se it. DatabaseName will be the name of the existing BDE or ODBC alias that you must already have set up.

Now let's go to the SQL part:
SQL is is very database specific, although it was supposed to be a standard. As you'll be using MS-SQL, I'll simply give you general guidelines on how to use SQL form Delphi. For the MS-SQL-specific features, you must refer to the MS-SQL on-line help or manuals.

In order to make a SQL query from Delphi, you use the TQuery component. The TQuery component connects to the TDatabase component we have already set up. So, the Database property of the TQuery component(s) will be the same of the AliasName property you defined.

Just put place the SQL statements in the SQL property of the TQuery component. You can only have one query per component at a time. Thus, if you want to make many SQL queries but use only one component, here's what to do:

With Query1 do

Only if you have a SELECT statement in a TQuery you must open the query with TQuery.open. If you have a CREATE, UPDATE or DELETE statement in the query, then you must use the ExecSQL method to activate the query.

The URL below is an excellent information on general SQL and can provide you with much more information than I could do here:




Author Comment

ID: 1389369
Thanks for help

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

719 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