Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does the MySQL statement look like

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about what the MySQL sentence is like. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Select database USE

When you first linked to MySQL, there was no database open for you to use, but we need to select a database to do the following.

Method: USE statement

USE Mdatabase

Only in this way can we open the database and read the data in it.

two。 Display information SHOW

MySQL extracts information from internal tables

SHOW database

Returns a list of available databases

SHOW tables

Returns a list of tables in the database

SHOW columns from table

Show table columns

3. Create table CREATE TABLE

Basic syntax:

/ / by LMYCREATE DATABASE database name; / * create database * / USE database name; / * connect database * / CREATE TABLE table name 1 (column name 1 data type requirements, column name 2 data type requirements, column name 3 data type requirements. PRIMARY KEY (primary key) / * Note, there is no comma here * /)

Take my database homework as chestnut:

(environment, MySQL workbench)

Request:

Create a database called "my_own_movie_database". After that, create the following tables, and then insert the corresponding input

First, open workbench and add a new SQL file

After that, write the sql statement in the new file

Write the corresponding sql statement, after writing, you will find on the left side, there is a new database, click in, you can also see the table you built

The complete code is as follows:

Drop database if exists `my_own_movie_ database`; create database `my_own_movie_ database`; USE `my_own_movie_ database`; CREATE TABLE `movieexec` (`name` char (30) DEFAULT NULL, `address` varchar (100) DEFAULT NULL, `cert` int (11) NOT NULL DEFAULT'0', `netWorth` int (11) DEFAULT NULL, PRIMARY KEY (`cert`) ENGINE=InnoDB DEFAULT CHARSET=utf8 # # Data for table "movieexec" # INSERT INTO `movieexec` VALUES ('Calvin Coolidge','Fast Lane',123,20000000), (' Merv Griffin','Riot Rd.',199,112000000), ('Stephen Spielberg','123 ET road',222,100000000), (' Ted Turner','Turner Av.',333,125000000), ('George Lucas','Oak Rd.',555,200000000), (' Jane Fonda','Turner Av.',567,200000000) # # Source for table "movies" # CREATE TABLE `studio` (`name` char (30) NOT NULL DEFAULT', `address` varchar (100) DEFAULT NULL, `presC` int (11) DEFAULT NULL, PRIMARY KEY (`name`)); # # Data for table "studio" # INSERT INTO `studio`studio` VALUES ('MGM','MGM Boulevard',123), (' Fox','Fox Boulevard',199), ('Disney','Disney Boulevard',222), (' USA Entertainm','USA Entertainm Boulevard',333), ('Paramount','Paramount Boulevard',555) CREATE TABLE `produces` (`title`NOT NULL DEFAULT'', `year`int (11) NOT NULL DEFAULT '0years, `yearth` int (11) DEFAULT NULL, `movieType` char (10) DEFAULT NULL, `studioName` char (30), `producerC`int (11) DEFAULT NULL, PRIMARY KEY (`title`, `year`), foreign key (studioName) references studio (name) on delete cascade) # # Data for table "movies" # INSERT INTO `roomes` VALUES ('Empire Strikes Back',1980,111,'drama','Fox',555), (' Gone With the Wind',1938,null,'drama','MGM',123), ('Logan\' s run',1977,120,'drama','MGM',888), ('Pretty Woman',1990,119,'drama','Disney',999), (' Star Trek',1979,132,'sciFic','Paramount',444), ('Star Trek: Nemesis',2002,116,'sciFic') 'Paramount',321), (' Star Wars',1977,124,'sciFic','Fox',555), ('Terms of Endearment',1983,132,'drama','MGM',123), (' The Man Who Wasn\'t There',2001,116,'comedy','USA Entertainm',777), ('The Usual Suspects',1995,106,'drama','MGM',999) # # Source for table "moviestar" # CREATE TABLE `roomestar` (`name` char (30) NOT NULL DEFAULT'', `address` varchar (255) DEFAULT NULL, `gender` char (1) DEFAULT NULL, `roomdate`date DEFAULT NULL, PRIMARY KEY (`name`) ENGINE=InnoDB DEFAULT CHARSET=utf8 # # Data for table "moviestar" # INSERT INTO `roomestar` VALUES ('Alec Baldwin','Baldwin Av.','M','1977-06-07'), (' Debra Winger','A way','F','1978-05-06'), ('Harrison Ford','Prefect Rd.','M','1955-05-05'), (' Jack Nicholson''s','X path','M','1949-05-05'), ('Jane Fonda','Turner Av.','F' '1977-07-07') # # Source for table "starsin" # CREATE TABLE `starsin` (`movieTitle` char', `movieYear` int (11) NOT NULL DEFAULT'0), `starName` char (30) NOT NULL DEFAULT'', PRIMARY KEY (`movieTitle`, `movieYear`, `starName`) ENGINE=InnoDB DEFAULT CHARSET=utf8 # # Data for table "starsin" # INSERT INTO `starsin` VALUES ('Empire Strikes Back',1980,'Harrison Ford'), (' Star Wars',1977,'Carrie Fisher'), ('Star Wars',1977,'Harrison Ford'), (' Star Wars',1977,'Mark Hamill'), ('Terms of Endearment',1983,'Debra Winger'), (' Terms of Endearment',1983,'Jack Nicholson'), ('The Usual Suspects',1995,'Kevin Spacey'); # # Source for table "studio" # 4. Insert data INSERT

The basic way of writing:

INSERT INTO table name 1 VALUES (data 1, data 2, data 3.), (data 1, data 2.).

Finally, run, shortcut key: Ctrl + Shift+Enter

In this place, I was stunned that I didn't know how to operate until the course was almost finished. Crying to death, the first half of the semester can not install the software, the second half of the semester every day why can not build a watch … )

After the table is built, you can see that the contents of the table

The above is what the MySQL sentence shared by the editor is like. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report