当前位置:网站首页>Bi SQL drop & alter
Bi SQL drop & alter
2022-06-25 01:15:00 【Powerbi white tea】

Drop & Alter
Drop, Cancel the operation ;Alter, update operation .
stay PowerBI in , If we modify some data cleaning operations , Just open the advanced editor to view M Language , You can modify and delete specific statements .
But in the database warehouse , We often need the help of Drop and Alter Or other statements to modify the data warehouse .
Why can't we be in a data warehouse like PowerQuery Do the same in ?
In fact, this is related to the positioning of the two .
PowerQuery The positioning of , Is aimed at PowerView To serve , although PowerQuery Self system , It can be called a mini data warehouse , But in general , The data we get from the standard data warehouse are relatively clean data .
SQL Servers The positioning of , It is one of the international basic database languages , Its positioning is a large data warehouse . In the standardized standards of data governance , The data warehouse must be stable 、 Continuously provide data source .
therefore , For the sake of database stability , If we need to modify and adjust the logic of the data warehouse , There must be a set of standardized operation processes and specialized logic modification statements .
grammar
Drop grammar :
1. Delete index :
DROP INDEX The index name ON The name of the table
2. Delete table :
DROP TABLE The name of the table
notes : This operation , Will delete the structure of the table 、 Properties and index !
3. Delete database :
DROP DATABASE Database name
4. Keep the table structure , Delete data only :
TRUNCATE TABLE The name of the table
Alter grammar :
1. Add columns to the table :
ALTER TABLE The name of the table
ADD Column name data type
2. Delete the column in the table :
ALTER TABLE The name of the table
DROP COLUMN Column name
3. Change the data type of the column in the table :
ALTER TABLE The name of the table
ALTER COLUMN Column name data type
Constraints Add
White tea has shared several types of constraints before , In fact, there were additional Drop and Alter Operation of the , Considering the classification problem , White tea decided to put it in this issue .
All the following syntax , When the table has been created , We need to make changes to the constraints .
- UNIQUE( only ) to update : Add unique constraint :
ALTER TABLE The name of the table
ADD UNIQUE ( Column name )
Add multiple column unique constraints :
ALTER TABLE The name of the table
ADD CONSTRAINT uc_ Constraint name UNIQUE ( Column name , Column name ...)
Undo unique constraint :
ALTER TABLE The name of the table
DROP CONSTRAINT uc_ Constraint name
- PRIMARY KEY( Primary key ) to update :
Add a primary key constraint :
ALTER TABLE The name of the table
ADD PRIMARY KEY ( Column name )
Add multiple column primary key constraints :
ALTER TABLE The name of the table
ADD CONSTRAINT pk_ Constraint name PRIMARY KEY ( Column name , Column name ...)
Undo the primary key constraint :
ALTER TABLE The name of the table
DROP CONSTRAINT pk_ Constraint name
- FOREIGN KEY( Foreign keys ) to update :
New foreign key constraint :
ALTER TABLE The name of the table
ADD FOREIGN KEY ( Column name )
REFERENCES Primary key table ( Column name )
Add multiple column foreign key constraints :
ALTER TABLE The name of the table
ADD CONSTRAINT fk_ Constraint name
FOREIGN KEY ( Column name )
REFERENCES Primary key table ( Column name )
Undo the foreign key constraint :
ALTER TABLE The name of the table
DROP CONSTRAINT fk_ Constraint name
- CHECK( Check ) to update :
Add check constraint :
ALTER TABLE The name of the table
ADD CHECK ( Column name Comparison symbol " Conditions ")
Add multi column check constraint :
ALTER TABLE The name of the table
ADD CONSTRAINT chk_ Constraint name CHECK ( Column name Comparison symbol " Conditions " AND Column name Comparison symbol " Conditions " ......)
Undo check constraint :
ALTER TABLE The name of the table
DROP CONSTRAINT chk_ Constraint name
- DEFAULT( The default value is ) to update :
New default value constraint :
ALTER TABLE The name of the table
ALTER COLUMN Column name SET DEFAULT ' The default value is '
Undo the default value constraint :
ALTER TABLE The name of the table
ALTER COLUMN Column name DROP DEFAULT

That's the end of this issue , No use cases , Because we do BI In fact, it is rare for the front end to use such operations , We are more simply using query aggregation statements .
Of course , Yes ETL And interested partners of the data warehouse can have a try .


This is white tea , One PowerBI Beginners .

边栏推荐
猜你喜欢

Zuckerberg demonstrated four VR head display prototypes, and meta revealed the "family" of metauniverse

If the order has not been paid for 30 minutes, it will be automatically cancelled. How can I achieve this?

JS Chapter 1 Summary

I brush the question I - copy the linked list with random pointer

Assembly language (4) function transfer parameters

Preliminary understanding of qtoolbutton

51单片机多机通信
最新QQ微信域名防红PHP程序源码+强制跳转打开

2022 melting welding and thermal cutting recurrent training question bank simulated examination platform operation

Scala IO read by character
随机推荐
Scala trait construction mechanism
Bi SQL constraints
天书夜读笔记——深入虚函数virtual
Bi skill - judge 0 and null
vb学习什么[通俗易懂]
2022r1 quick opening pressure vessel operation test questions and answers
activity生命周期
Using bindservice method to pause music playing
LLVM TargetPassConfig
丹麥技術大學首創將量子計算應用於能源系統潮流建模
这个国庆!腾讯云WeCity陪您一同出行,点亮城市地标...
Scala trait inheritance class
欢迎来到联想智能大屏的新世界
Contentresolver, get the SMS content
Basic knowledge of assembly language (2) -debug
QT electronic clock
Tencent cloud wecity Industry joint collaborative innovation to celebrate the New Year!
[live review] 2022 Tencent cloud future community city operator recruitment conference and SaaS 2.0 new product launch!
Library management system code source code (php+css+js+mysql) complete code source code
QT (35) - operate excel qxlsx qaxobject