SQL from zero to quick mastery of "basic statement"

Source: Internet
Author: User

1. Using the T-SQL statement to create the data table authors, enter the following statement.

CREATE TABLE Authors

{

auth_id int PRIMARY key,--data table primary key

Auth_name VARCHAR () not null unique,--author name, cannot be empty

Auth_gender tinyint not NULL DEFAULT (1)--author Sex: male (1), female (0)

};

2. Add a new field with the name Auth_note in the Authors table, the field data type is varchar (100), the null value is allowed, and the input statement is as follows.

ALTER TABLE Authors

ADD auth_note VARCHAR (+) NULL

3. In the authors table, modify the field named Auth_phone, change the data type to varchar (15), and enter the following statement.

ALTER TABLE Authors

ALTER COLUMN Auth_phone VARCHAR (15)

GO

4. Delete the Auth_phone field in the Authors table and enter the following statement.

ALTER TABE Authors

DROP COLUMN Auth_phone

5. Define the table table_emp and set the e_id field in the table as the primary key column, and enter the following statement.

CREATE TABLE Table_emp

(

e_id CHAR (PRIMARY KEY),

E_name VARCHAR (+) not NULL,

E_deptid INT,

E_phone VARCHAR (CONSTRAINT) Uq_phone UNIQUE

);

6. Delete the primary KEY constraints and uniqueness constraints in the member table, and the T-SQL statements are as follows.

ALTER TABLE Member

DROP CONSTRAINT Pk_member,uq_firstname

7. Delete the authors table from the test database and enter the following statement.

Use Test

GO

DROP TABLE Authors

SQL from zero to quick mastery of "basic statement"

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.