Sei sulla pagina 1di 3

primary and foreign key - good to have them primary key - applied on column which is unique in database e.g.

in axtria emp id is unique foreign key - dependent on something e.g project code cannot be assigned in axtria unless the person is on axtria rol l csv/text/Flat format is used so as to prserve the format of data (eg zip-code, I MS id) Import/export wizard Data Source needs to be changed -flat file source (text)/access/excel and corres ponding path needs to be provided Errors because of excel versions - reconvert the file to text format Destination - server where data needs to be imported Authentication - by default windows we can change the name and properties of database before completion of import Refresh the database to see the imported table in the list Errors - Truncation (Solution - increase the length of column while importing) ( bydefault length for any field is 50) (always try to read it as a text file) - Always read the error report (sometimes the error is just due to insuff icient disk space) Excel helps in importing/exporting multiple datasets in one go (multiple tabs wi th corresponding tables at once) SSIS package helps to auomate the process of importing SSRS package helps to automate the process of exporting Data types: Numeric - Float/int/numeric(digits,decimal) Sring - Varchar(max length) - variable length char (fixed length) - wil append spaces to account for lack of length Datetime - yyyy/mm/dd hh:mm:ss Unicode - nvarchar (maxlength) - alphanumeric values of variable length Money is also a datatype name (nvarchar, null) - null here inplies that this column can also have null va lues. (nvarchar, not null) - no null value can be there four basic things in sql - Select(only reading and not modifying)/update/insert /Delete select -from - where (input filtering)- group by (rolling up) - having (output f iltering) Color coding Blue - SQL Key words Pink - Mathematical ops Red - Hard coded/input values Grey - Logical operator Black - table/column names

Session-2 Where clause - Almost all operators can be used with it (in, between, like, not, <>) % for any length,

_ for one character, multiple _ can be used to specify the no. of characters [] for a specified range eg. [A-F], [^] for not within the specified range eg. [^a-f] are all wildcards Placement of brackets are important in the filtering criteria Order by <List of Variables> asc or desc ( default choice is ascending) (like so rting in excel) Cannot use alias command with order by No wildcards in SQL for selecting but only for sorting Creating a table in SQL CREATE TABLE <TABLE NAME> ( NAME VARCHAR(50) .........) or Select -- into -- from -- where -String Functions: Len, Left, right, ltrim, rtrim, substring, lower, upper single quotes '' to be used in SQL to denote strings ASCII structure is followed PATINDEX, REPLACE, CHARINDEX Date Functions : Getdate day month Year datepart () dateadd() datediff() Mathematical Functions Rand, Exp, Round, Floor, Ceiling, Log, Log10 Aggregation Functions: count, max, min, sum, count distinct, avg Group By State, City will give distinct state-city combinations (like remove dup licates command in excel) select from where group by having (remember this order) all the variables that appear in select statement must appear in group by (unles s they have an aggregate function for them) distinct fetches the unique combinations of the variables like Group by To reduce redundant data we divide the data into different tables - hence we nee d joins common field between different tables is called foreign key NULL denotes missing value.. blank dentotes "" value

inner join left outer join right outer join full outer join cross join (multiplies the records) isnull replaces null value with the required value (such as 0) the record having null value in joined column gets excluded in the final result

Potrebbero piacerti anche