Two methods of establishing a database structure

xiaoxiao2021-03-06  82

Q: Now my situation is: I have installed SQL Server, I have a installer (of course to write with Delphi), I need to create a database name MyServer1 on SQL and then use three of the database. What is the SQL statement creates a structure? If someone can solve the problem, willing to add 200 points!

method one:

-------------------------------------------------- ---------------------------------------- I have made a similar thing, and many domestic The famous software companies also use the same way. You can make an external configuration program, or in this program (it is very righteous) 1: Connect Master. If you do not successfully report the error exit. 2: In Master, execute the library operation if not exists (Select * from sysdatabases where name = 'testserver') Create Database TestServer3: Connect TestServe, built in the user, build a table, reference method: SQL statement is read from the script file . Note question: One of the brothers in front said that the table can be built together, stored procedures and views best one. The above method is universal, regardless of the connection method (BDE, ADO), and more hands to do, in fact, you are not difficult. Give me a message. -------------------------------------------------- -----------------------------------------

-------------------------------------------------- ---------------------------------------- this problem is very simple, directly in Delphi Calling isql.exe suggests that it is best to control the server running, otherwise the database physical file read and write permission will be troublesome. How do I do not need to teach, I believe in your ability. Give it. -------------------------------------------------- -----------------------------------------

-------------------------------------------------- ------------------------------------------ I think jamlog's way should be feasible, It is said that the specific point is to generate such a command in the program: isqlw -s (local) -d myserver1 -u sa -p -id: /program/view1.sql -od: /program/View1.txt then execute it, then Decision is successful in the output file specified by the -O parameter, then further processing. -------------------------------------------------- ----------------------------------------

-------------------------------------------------- -------------------------------------- first build a TSQL script file, the head is used as follows Statement

use mastergoif (exists (select name from sysdatabases where upper (name) = 'DBNAME')) drop database DBNAMEgocreate database DBNAMEgouse DBNAMEgo ... in Delphi program, you can call ISQL to run the script shellexecute (nil, 'open', ' Isql ', params,' ', sw_hide; or use Winexec Bar specific parameters you can watch MS SQL about ISQL help

The CreateProcess API function is called in Delphi (this function is in Windows.Pas unit) ------------------------------- -------------------------------------------------- ---------

Method Two:

---------------------------------------------- ----------------------------------- I just made a guide to a new database, this is a creation table Function (read .sql file):

Function Tsqlmanagefrm.createTable: Boolean; Var i: integer; str: string;

Begin Result: = false; adoq1.close; try adoq1.close; adoq1.sql.clear; adoq1.sql.LoadFromFile (extractFilepath (Application.exename) 'Database.sql'); for i: = 0 to adoq1.sql .Count - 1 DO

if Trim (adoq1.sql [i]) = 'go' Then Adoq1.sql [i]: = ''; // str: = adoq1.sql.text; // SQL Server generated script has 'go' But Delphi does not recognize. When you generate a script, you must create a table, view, and store procedures, otherwise Delphi will report an error! Adoq1.execsql; Result: = true; except messagebox (getActiveWindow (), 'creation table error!', 'Warning', MB_OK MB_ICONEXCLAMATION; EXIT; END;

End; ------------------------------------- Read. SQL file ------- -------------------------------------

转载请注明原文地址:https://www.9cbs.com/read-124045.html

New Post(0)