T-SQL Subtotal _02 keyword _02

Source: Internet
Author: User
Tags one table

The last time we talked about the add create and insert in SQL, what do we do if we want to delete and modify it?

First of all, we have to clear one thing, that is the database object and the difference between the data , this is actually mentioned in the last time, because just started to write, think of where to write, essays, essays, the last time there are many created also forget, haha. Don't blame it.

database Objects are part of the database and are mainly

1. The table should be the most basic object in the database, which is the object used by the database to store formatted data. The tables in the database are similar to the tables we use in our daily lives, which are also made up of rows and columns (column). Columns are made up of homogeneous information, each column is also called a field, and the title of each column is called the field name. The row includes several column information items. A row of data is called one or a record, and it expresses a meaningful combination of information. A database table consists of one or more records, and a table without records is called an empty table. Each table typically has a primary key that uniquely identifies a record. 2. An indexed index is a unique marker for each data record in a table, and is based on the order in which the specified database table column is set up. It provides a way to quickly access data, and can supervise the table's data so that the data in the column to which it is indexed is not duplicated. such as clustered indexes. 3. The view view looks identical to the table, with a named set of fields and data items, but it is actually a virtual table that does not actually exist in the database. Views are generated by querying a database table, which restricts the data that users can see and modify. This shows that the view can be used to control user access to data, and to simplify the display of data, that is, through the view only the data needed to display information. 4. Chart charts are the relationships between table tables in a database that you can use to edit the relationships between tables and tables. This simplifies access to multiple tables if there is more than one table in a database, instead of being orphaned, it creates a connection. 5. The default default value is to assign a predetermined value to a column or column data item that does not specify its specific value when a column is created in the table or when data is inserted. 6. Rule rules are limitations, but it is important to note that the rules in the database restrict the data information in the database tables only for the columns in the table. 7. Trigger triggers are triggered by events, can query other tables, and can contain complex SQL statements. They are primarily used to enforce complex business rules or requirements. It can also be used to enforce referential integrity so that when rows are added, updated, or deleted in multiple tables, the relationships defined between the tables are preserved. 8. Stored procedure stored procedures are a set of SQL program statements that are pooled for the completion of a particular function and are compiled and stored in a database SQL program. 9. The user is the user who has access to the database. Then it's the database. Data, in general, data exists in database tables, and basically our SQL operations are ultimately about manipulating the data in the database. So back to the previous article, create a database object generally with Create, and then insert the data in the words used to insert. Delete is also the same, delete database objects generally with drop, delete data with delete. such as: Drop Database xxx;drop Table xxx;drop View xxx; Delete from table where ... The above is said to delete, modify the same words, modify the object with alter, modify the data with update. such as: ALTER table1 ALTER COLUMN XXX int null--Modify the table's column type update table1 set xxx = YYY where ...--Modify the value of the XXX field that meets the criteria for yyy speaking of Alter, some about Modify the table related, for example: ALTER table Distributors ADD address varchar (30); --Add a varchar column to the SQL Server table
ALTER TABLE Distributors DROP COLUMN address RESTRICT; --Delete a field from the SQL Server table
ALTER TABLE Distributors RENAME COLUMN address to City; --Change the column name of the table
ALTER TABLE Distributors RENAME to suppliers; --Change the name of the table
ALTER TABLE distributors ALTER COLUMN Street SET not NULL; --Add a non-null constraint to a field
ALTER TABLE distributors ALTER COLUMN Street DROP not NULL; --Remove a non-null constraint from a field
ALTER TABLE Distributors ADD CONSTRAINT zipchk CHECK (char_length (zipcode) = 5); --Add a CHECK constraint to a table
ALTER TABLE Distributors DROP CONSTRAINT Zipchk; --Delete a table and all its child table's audit constraints
ALTER TABLE Distributors ADD CONSTRAINT DISTFK FOREIGN KEY (address) REFERENCES addresses (address) MATCH full; --Add a FOREIGN KEY constraint to the table
ALTER TABLE Distributors ADD CONSTRAINT dist_id_zipcode_key UNIQUE (dist_id, ZipCode); --Add one (multi-field) Unique constraint to the table

T-SQL Subtotal _02 keyword _02

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.