In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the creation method of database table, which is very detailed and has certain reference value. Friends who are interested must finish reading it.
In the database, you can use the "CREATE TABLE" statement to create a table with the syntax format "CREATE TABLE table name (column name 1 data type (maximum length) 1 [, …] column name n data type (maximum length) n);".
The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.
Creation of tables in database
The process of creating a data table is not only the process of specifying the attributes of the data column, but also the process of implementing data integrity (including entity integrity, referential integrity, and domain integrity) constraints.
Basic grammar
In MySQL, you can use CREATE TABLE statements to create tables. Its grammatical format is:
CREATE TABLE ([table definition options])
The format of "Table definition options" is:
[,...]
The main syntax and usage instructions of the CREATE TABLE statement are as follows:
CREATE TABLE: used to create a table with a given name, you must have permission for the table CREATE.
Specifies the name of the table to be created, given after CREATE TABLE, and must conform to the naming convention for identifiers The table name is specified as db_name.tbl_name to create the table in a specific database. It can be created in this way, regardless of whether there is a current database or not. You can omit db-name when you create a table in the current database. If you use a quoted distinguished name, the database and table names should be in quotation marks, respectively. For example, 'mydb'.'mytbl' is legal, but' mydb.mytbl' is illegal.
A table creation definition consisting of a column name (col_name), a column definition (column_definition), and a possible null value description, integrity constraint, or table index
Size: specifies the maximum length of the columns in the table.
By default, the table is created into the current database. An error occurs if the table already exists, there is no current database, or the database does not exist.
Tip: when you create a table using CREATE TABLE, you must specify the following information:
The name of the table to be created is case-insensitive and cannot use keywords in the SQL language, such as DROP, ALTER, INSERT, and so on.
The name and data type of each column (field) in the data table. If you create multiple columns, separate them with commas.
Example:
Select the database test_db in which to create the table
Mysql > USE test_db;Database changed
Create an tb_emp1 data table
Mysql > CREATE TABLE tb_emp1-> (- > id INT (11),-> name VARCHAR (25),-> deptId INT (11),-> salary FLOAT->); Query OK, 0 rows affected (0.37 sec)
Use the SHOW TABLES statement to see if the datasheet was created successfully
Mysql > SHOW TABLES;+-+ | Tables_in_test_db | +-+ | tb_emp1 | +-+ 1 rows in set (0.00 sec) above are all the contents of this article "how to create database tables". Thank you for reading! Hope to share the content to help you, more related knowledge, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.