Today we are going to insert tables and records without creating or inserting into the command window.
Until now, creating tables and inserting records in the command window had to proceed by entering a statement like this:
After selecting a database
Create a table like this
CREATE TABLE table name( name varchar(10), age int(5) );
Then insert the record.
INSERT INTO table name(field name)
VALUES (field value 1 , field value 2,...);
That completes one record line.
In the above statement, after inserting the table name, it writes the field name that was specified between(). It only needs to be done once when writing the first record.
When inserting the next record, insert into table name immediately after enter.
This is done by creating values (field value 1, field value 2).
Now let's do a batch run. Batch run is the process of creating a table directly in the editor and entering records in the editor.
First create a table. In the editor you're using
Enter the following: This is not a cmd window, but an editor (any editor such as ATOM, Notepad ++, Notepad, phpstorm, etc.).
CREATE TABLE my_smart_devices( num int not null auto_increment, name varchar(20), thenumberofcpu varchar(20), company varchar(20), primary key(num));
auto_increment is a setting that automatically increments the value by one. This is to avoid overlapping values.
Used to specify a unique password for the record.
If you entered as above, now save
On macOS, save as smart.
sql file name and extension in / Application / MAMP / Library / bin / folder In windows10, save as smart.sql file name and extension in c: / mamp / bin / mysql / bin folder.
Now connect to MySQL and create a database called smart.
CREATAE DATABASE smart;
Will create a database called smart.
If you type in and confirm, a smart database exists.
Type exit to exit mysql.
And type macOS users:
sudo ./mysql -uroot -proot smart < smart.sql
mysql -uroot -proot smart < smart.sql
As you can see, the file containing the table creation source called smart.sql is put into the smart database.
Then the table is created.
Let's see if there is a my_smart_devices table in the smart database.
go to mysql and use smart; Type show tables; Will enter the my_smart_devices table.
So let's see if the fields are in place with desc.
Then let's search for a specific record for the next course!