Sql

318 views

Published on

Published in: Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
318
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sql

  1. 1.  1979,IBM researchers created a simple non procedural language called “Structured English Query Language or SEQUEL”  1980’s ANSI &OSI (organizations deal with Standards) standardized version called Structured query language & Sql  Pronounced as “sequel”  Latest versions is SQL -99 ,SQL -92 is current universally adopted standard
  2. 2.  A relational database uses the concept of linked two dimensional tables which comprise of rows and columns .  a user can draw relationships between multiple tables and present the output as a table again.  A user of a relational database need not understand the representation of data in order to retrieve it  Relational programming is non procedural.
  3. 3.  Programming language are procedural if they use programming elements such as conditional statements (if-then-else, do- while etc.)  SQL has none of these types of statements , hence Non procedural. My sql and MSqL are DBMS  Procedural & non Procedural
  4. 4.  It is the process where a database is designed in a way that removes redundancies and increases the clarity in organizing data in a database  It raises the eficiency of the database in terms of management data storage and scalability
  5. 5.  For E-g :Contacts Database  Create a database with the following fields  First name,Last name,Birth Date, street ,address,City,State,Zip,Country, TelephoneHome,Telephonework,Email, Companyname,Designation  Keep the FirstName,Lastname&Birthdate in one table  Address related data in another  Company details in another  E-mails in another  Telephones in another
  6. 6.  INT(length) integer with unsigned range 0-429467295 a signed from -2147483648-2147483648  Decimal (length, decimal)-floating point number with the range of the Double type that is store as a char field typed  Date YYYY-MM-DD  Time HH:MM:DD  DATETIME:YYYY-MM-DD-HH:MM:SS  Year YYYY or YY  Varchar (length)A fixed length text string (255 character Max)where unused trailing spaces are removed before storing
  7. 7.  Run the command line tool “Mysql”  MySQL>use contacts  MySQL>CREATE TABLE names(contact_idSMALLINT NOT NULLAUTO_INCREAMENTPRIMARYKEY, FIRSTNAME CHAR(20),LastNameCHAR(20),Birthdate DATE);
  8. 8.  Mysql>CREAT TABLE address(contact_id SMALLINT NOT NULL PRIMARY KEY,streetAddressCHAR(50),city CHAR (20),state CHAR(20),Zip CHAR(15),country CHAR (20))  Mysql>CREAT TABLE telephones(contact_Id SMALLINT NOT NULL PRIMARY KEY,TELEPHONEHOME INT (20));  Mysql>CREAT TABLE email (Contact_Id SMALLINT NOT NULL PRIMARYKEY,Email CHAR(20));  Mysql>CREAT TABLE company details(contact_id SMALLINT NOT NULL PRIMARY KEY,companyName CHAR(25),Designation CHAR(15))
  9. 9.  A Foreign Key is a Field which is also the Primary Key in Another table. This is Known commonly as referential integrity.  To see the tables inside the database:  Mysql>SHOW TABLES;  ∣ Tables in contacts ∣ ∣ address∣ ∣ Company_details∣ ∣ email ∣ ∣ names ∣ ∣ Telephones∣
  10. 10.  Mysql>SHOWCOLUMNSFROM address; Insert data one row at a time  Mysql>INSERT INTO names(FirstName,LastName,BirthDate)VALUES (‘raj’,‘kumar’,‘1980-10-14’); To see what the data looks like inside the table- using select command  Mysql>select*fromNAMES; ∣ Contactid ∣ FirstName ∣ LastName ∣ BirthDate ∣ ∣ 2 ∣Raj ∣ kumar ∣1980-10-14 ∣
  11. 11.  Mysql>select*FROMnamesWHEREcontact_id>1 ∣ Contact_id ∣FirstName ∣Lastname ∣BirthDate ∣ ∣ ∣ 3 ∣sam ∣ son ∣1981-4-12 ∣ 2 ∣sanu ∣gupta ∣1987-5-12 ∣  Mysql>select*FROMnamesWHEREBirthDate>’1973-03- 06’ ∣ Contact_id ∣FirstName ∣LastName ∣BirthDate ∣ ∣ 3 ∣sam ∣ son ∣1981-4-12 ∣ ∣ 2 ∣sanu ∣gupta ∣1987-5-12 ∣  Mysql>selectFirstName,LastNameFROM names WHERE LastName LIKE’C%’; ∣ FirstName ∣LastName ∣ ∣ Jai ∣ chopra ∣ ∣ Diksha ∣chaubey ∣
  12. 12.  Mysql>SELECTFirstName,LastNameFrom names WHERE LastName LIKE ‘_roy’ ∣ FirstName ∣LastName ∣ ∣ Bikram ∣Roy ∣  Mysql>SELECT contact_id FROM names WHERE LastName IN(“Diaz’,’Carrera’) ∣ Contact_ID ∣ ∣ 3 ∣ ∣2 ∣
  13. 13.  Mysql>SELECT count(*)FROM names; ∣count(*) ∣ ∣3 ∣  Mysql>SELECT count (FirstName)FROM names; ∣count(FirstName) ∣ ∣3 ∣  Mysql>SELECT*FROMnamesWHEREcontact_id>=1 ∣ Contactid ∣ FirstName ∣ LastName ∣ BirthDate ∣ ∣ 2 ∣Raj ∣ kumar ∣1980-10-14 ∣
  14. 14.  Mysql>select FirstName,LastName FROM names WHERE contact_id BETWEEN 2and3 ∣ FirstName ∣LastName ∣ ∣ Jai ∣ chopra ∣ ∣ Diksha ∣chaubey ∣
  15. 15.  mysql>ALTER TABLE names ADD Age SMALLINT;  mysql>ALTER TABLE names CHANGE COLUMN Age Age TINYINT;  TO Rename a Table:  mysql>ALTER TABLE names RENAME AS mynames  Mysql>ALTER TABLE names RENAME AS names
  16. 16.  Mysql>update names SET Age=‘23’WHEREFirstName=‘Tia’;  Mysql.SELECT*FROM names; ∣ Contactid ∣ FirstName ∣ LastName ∣ BirthDate ∣Age ∣ ∣ 2 ∣Tia ∣ kumar ∣1980-10-14 ∣23 ∣ ∣ 3 ∣sam ∣ son ∣1981-4-12 ∣24 ∣
  17. 17.  Mysql>DELETE FROM names WHERE Age=23  Mysql>select*FROM names ∣ 3 ∣sam ∣ son ∣1981-4-12 ∣24 ∣  Mysql>DELETE FROM names;  Mysql>SELECT*FROM names; Empty set
  18. 18.  Mysql>DROP TABLE names;  Mysql>SHOW TABLE names;  ∣ Tables in contacts ∣ ∣ address∣ ∣ Company_details∣ ∣ email ∣ ∣ Telephones∣
  19. 19.  Normalisation Example  We will demonstrate the process of normalisation (to 3NF) by use of an example. Normalisation is a bottom-up technique for database design, normally based on an existing system (which may be paper-based). We start by analysing the documentation, eg reports, screen layouts from that system. We will begin with the Project Management Report, which describes projects being worked upon by employees. This report is to be 'normalised'. Each of the first four normalisation steps is explained.  Next: Step 1

×