To create a SQL script file that contains SQL commands

Source: Internet
Author: User
Tags create index


SQL scripts are SQL statements that contain one or more SQL commands, and we can put these SQL scripts in a text file (which we call "SQL script files") and execute the SQL script file with the relevant commands. The basic steps are as follows:
1. Create a SQL script file containing SQL commands
The file contains a few columns of SQL statements, each ending with A; end, the file content example is as follows:
--Create a table and annotate with "--"
CREATE TABLE Table name
(
Guid Varchar ($) NOT null primary key,
Title Varchar (255),

) Type=innodb;

--Add field status to Table A
ALTER TABLE A add Status TinyInt default ' 0 ';

--Create an index on table a
Create INDEX xx_taskid_1 on A (ID_);
--Add a record to table a
Insert into A (Id,parentid, name) VALUES (1, 0, ' name ');
--After adding, modifying, and deleting data, it is possible to commit a transaction
Commit;

2. Execute SQL script file
Method one
executes with the cmd command (under Windows, UNIX or Linux under its console)
"MySQL Bin directory" \mysql–u user name –p password –d database < "SQL script file path full name" Example:
D:\mysql\bin\mysql–uroot–p123456-dtest<d:\test\ss.sql
Attention:
A, if the use database is used in a SQL script file, the-d database option can be ignored
B, if "MySQL Bin directory" contains spaces, you need to use "" "include, such as:" C:\Program files\mysql\bin\mysql "–u username –p password –d database <" SQL script file path full name "

method Two after entering MySQL console, use the source command to execute
Mysql>source "path full name of SQL script file" or mysql>\. "Path full name of SQL script file", example:
source D:\test\ss.sql or \. D:\test\ss.sql

Top
4
Step
1

To create a SQL script file that contains SQL commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.