An instance of building a library and building a table
The code is as follows |
Copy Code |
Drop database if exists school; Delete if there is school Create Database School; Build a library School Use school; Open Library School CREATE TABLE teacher//Create tables Teacher ( ID int (3) auto_increment NOT null primary key, Name Char (a) NOT NULL, Address varchar default ' Shenzhen ', Year Date ); Build Table End
The following is the Insert field Insert into teacher values (", ' Allen ', ' Dalian One ', ' 1976-10-10′ '); Insert into teacher values (", ' Jack ', ' Dalian II ', ' 1975-12-23′"); |
If you type the above command at the MySQL prompt, it's not easy to debug.
1, you can write the above command as is written in a text file, assume that the school.sql, and then copy to C:\, and in the DOS state into the directory [Url=file://\mysql\bin]\mysql\bin[/url], and then type the following command:
Mysql-uroot-p Password < C:\school.sql
If successful, there is no display on a single line, and if there is an error, there is a hint. (The above command has been debugged and you can use it only if you remove the comment.)
2, or enter the command line after the use of mysql> source c:\school.sql; You can also import the School.sql file into the database.
code is as follows |
copy code |
Drop database if exists school; If a school is present, delete the Create DATABASE school//build library school Use School;//Open Library school CREATE TABLE teacher//CREATE TABLE teacher ( ID int (3) auto_increment NOT NULL primary key, name Char (TEN) NOT NULL , address varchar ($) Default ' Shenzhen ', year date );//table End //below Insert Into the field insert into teacher values (', ' ' Glchengang ', ' ', ' ' Shenzhen ', ' 1976-10-10 '); insert into teacher values (' ", ' ' Jack ', ' Shenzhen One ', ' 1975-12-23 '; |
Note: In the construction of the table
1. Set the ID to a number field of length 3: Int (3), and let it automatically add one to each record: auto_increment; not null; and let him be the main field primary key.
2, set name to a length of 10 character field
3, the address set to the length of 50 character field, and the default value is Shenzhen.
4. Set year as Date field.