• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

SQL Begining!

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.
Thanks
0
ahmosa
Asked:
ahmosa
1 Solution
 
SlavakCommented:
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.




0
 
kretzschmarCommented:
hi ahmosa,

take a look to this sql-tutorial
http://www.intermedia.net/support/sql/sqltut.htm

its good for the basic understanding of the sql-language

meikl
0
 
simonetCommented:
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
PASSWORD=passoword

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
begin
   close;
   SQl.Clear;
   SQl.Add('SELECT NAME, COUNT(HITS), SUM(PAY) FROM HITMEN GROUP BY NAME HAVING NAME LIKE ''OSWALD%''');
   Open;
end;

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:

http://w3.one.net/~jhoffman/sqltut.htm

Yours,

Alex
0
 
ahmosaAuthor Commented:
Thanks for help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now