In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to write the sentence of adding fields in sql, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
What is the statement for adding fields to sql?
The standard SQL statement for adding a field to a data table is written as follows:
Alter table table name add (field type) [default 'input default'] [null/not null]
For example:
ALTER TABLE employee ADD spbh varchar (20) NOT NULL Default 0
It means to add the field spbh to the table employee, which is of type varchar, size 20, and is not allowed to be empty, and the initial default value is 0.
Extended data:
Other commonly used SQL statements:
1. Modify a field property in the data table and add comments to it.
Statement format:
Comment on column library name. Table name. Field name is' comments entered'
Example: if I want to add a comment to the document_type field of the test table in the ers_data library, the sql statement is:
Comment on column ers_data.test.document_type is' File Type'
2. Modify a field type in the data table.
Statement format:
Alter table table name modiy (field type [default 'input default'] [null/not null], field type [default 'input default'] [null/not null])
Modify multiple fields separated by commas.
Example: if you want to change the type of office classroom of a field in the teacher teacher table to char (20), and the default value is "office", the corresponding sql is:
ALTER TABLE teacher ALTER COLUMN classroom VARCHAR (20) NOT NULL default "Office"
3. Delete a field in the data table.
Statement format:
Alter table table name drop (field)
Example: to delete the field age in table student, you can use the following sql:
Alter table student drop age; thank you for reading this article carefully. I hope the article "how to write sentences for adding fields in sql" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.