SQL Learning Tip2

来源:互联网 发布:asp.net 抓取网页数据 编辑:程序博客网 时间:2024/05/21 22:49
1. alter table talbe_name add column column_name data_type (First/Before/Last/After/Fifth) (column_name)   Comments: set the new column in a certain position compared with "assigned column"2. alter table table_name rename to new_table_name3. alter table table_name change column old_column_name new_column_name data_type (Not null) (Auto_Increment),   add  Primary key (column_name)4. alter table table_name modify column column_name new_data_type5. alter table table_name drop column column_nameSummary:   'change' is used to change both name and datatype   'modify' is used to change datatype   'drop column' is used to remove a column in table   'rename' is used to rename the table.   6. Handy String function   Right(String, location)/Left(String, location): retrieve the part of the string   substring_index(location, 'character', times):  retrieve the part of the string   substring(your_string, start_position, length)   Upper(String)/Lower(String)   Reverse(String)/Ltrim(String)/RTrim(String)/Length(String)      Comments: all the functions just modify the returned result after querying.7. Case--End   SQL Statement:    Update table table_name set column_name =      Case          when condition1 then value1         when condition2 and condition3 then value2         ......         else valuen     end     8. Math Functions:   sum(),avg(), min(),max(),count()   SQL:     select first_name, sum(score) from cookie_sales group by first_name order by sum(score) desc (Limit number)     9. select * from tablename where column like '%keyword%'   *:  any number of unknown character   _:  one character of unknown character10:  between equals <= and >=;11. select * from tableName where column in (A,B,....)12. Not/<>:  not equal13. select * from nls_session_parameters where parameter = 'NLS_DATE_FORMAT';14. Lower()/Upper():15.   1NF:    a. Each row of data must contain atomic values    b. Each row of data must have a unique identifier named "Primary Key"       A primary key is a column in your table, that will make each record unique.        Not null, must have value when inserting,compact, can't be changed.    c. 16. Auto_increment17. Alter Table with a primary key  Sql:     alter table table_name      add column column_name column_type (not null) (auto_increment) (First),
原创粉丝点击