A collection of basic SQL Syntax (i)--data definition

Source: Internet
Author: User

Defining a basic table *********************************************

Create a "student" table student

CREATE TABLE Student

(Sno CHAR (9) PRIMARY KEY,

Sname CHAR (a) UNIQUE,

Ssex CHAR (2),

Sage SMALLINT,

Sdept CHAR (20)

);

Create a "curriculum" Course

CREATE TABLE Course

(Cno CHAR (4) PRIMARY KEY,

Cname CHAR (40),

Cpno CHAR (4),

Ccredit SMALLINT,

foreing KEY cpno REFERENCES Course (Cno)

)

Set up Student Timetable SC

CREATE TABLE SC

(Sno CHAR (9),

Cno CHAR (4),

Grade SMALLINT,

PRIMARY KEY (Sno, Cno),

Foreing KEY (Sno) REFERENCES Student (Sno),

Foreing KEY (Cno) REFERENCES Course (Cno),

);

Modify the base table *********************************************

Add the Entry Time column to the student table whose data class type is date

ALTER TABLE Student ADD s_enrrance DATE;

Change the age data type from character type to integer type

Alter TABLE Student ALTER COLUNM Sage INT;

Adding a course name must be a unique and worthy constraint

ALTER TABLE Course ADD UNIQUE (Cname);

Delete base table *********************************************

Delete Student Table

DROP TABLE Student CASCADE;

A collection of basic SQL Syntax (i)--data definition

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.